Blame


1 4b33cdd0 2015-11-30 stephen.d package p9p
2 4b33cdd0 2015-11-30 stephen.d
3 4b33cdd0 2015-11-30 stephen.d import (
4 4b33cdd0 2015-11-30 stephen.d "errors"
5 4b33cdd0 2015-11-30 stephen.d "fmt"
6 4b33cdd0 2015-11-30 stephen.d )
7 4b33cdd0 2015-11-30 stephen.d
8 4b33cdd0 2015-11-30 stephen.d // MessageRerror provides both a Go error type and message type.
9 4b33cdd0 2015-11-30 stephen.d type MessageRerror struct {
10 4b33cdd0 2015-11-30 stephen.d Ename string
11 4b33cdd0 2015-11-30 stephen.d }
12 4b33cdd0 2015-11-30 stephen.d
13 a0568195 2016-05-23 stevvooe // 9p wire errors returned by Session interface methods
14 4b33cdd0 2015-11-30 stephen.d var (
15 4b33cdd0 2015-11-30 stephen.d ErrBadattach = new9pError("unknown specifier in attach")
16 4b33cdd0 2015-11-30 stephen.d ErrBadoffset = new9pError("bad offset")
17 4b33cdd0 2015-11-30 stephen.d ErrBadcount = new9pError("bad count")
18 4b33cdd0 2015-11-30 stephen.d ErrBotch = new9pError("9P protocol botch")
19 4b33cdd0 2015-11-30 stephen.d ErrCreatenondir = new9pError("create in non-directory")
20 4b33cdd0 2015-11-30 stephen.d ErrDupfid = new9pError("duplicate fid")
21 4b33cdd0 2015-11-30 stephen.d ErrDuptag = new9pError("duplicate tag")
22 4b33cdd0 2015-11-30 stephen.d ErrIsdir = new9pError("is a directory")
23 4b33cdd0 2015-11-30 stephen.d ErrNocreate = new9pError("create prohibited")
24 4b33cdd0 2015-11-30 stephen.d ErrNomem = new9pError("out of memory")
25 4b33cdd0 2015-11-30 stephen.d ErrNoremove = new9pError("remove prohibited")
26 4b33cdd0 2015-11-30 stephen.d ErrNostat = new9pError("stat prohibited")
27 4b33cdd0 2015-11-30 stephen.d ErrNotfound = new9pError("file not found")
28 4b33cdd0 2015-11-30 stephen.d ErrNowrite = new9pError("write prohibited")
29 4b33cdd0 2015-11-30 stephen.d ErrNowstat = new9pError("wstat prohibited")
30 4b33cdd0 2015-11-30 stephen.d ErrPerm = new9pError("permission denied")
31 4b33cdd0 2015-11-30 stephen.d ErrUnknownfid = new9pError("unknown fid")
32 4b33cdd0 2015-11-30 stephen.d ErrBaddir = new9pError("bad directory in wstat")
33 4b33cdd0 2015-11-30 stephen.d ErrWalknodir = new9pError("walk in non-directory")
34 4b33cdd0 2015-11-30 stephen.d
35 4b33cdd0 2015-11-30 stephen.d // extra errors not part of the normal protocol
36 a0568195 2016-05-23 stevvooe
37 4b33cdd0 2015-11-30 stephen.d ErrTimeout = new9pError("fcall timeout") // returned when timing out on the fcall
38 4b33cdd0 2015-11-30 stephen.d ErrUnknownTag = new9pError("unknown tag")
39 4b33cdd0 2015-11-30 stephen.d ErrUnknownMsg = new9pError("unknown message") // returned when encountering unknown message type
40 4b33cdd0 2015-11-30 stephen.d ErrUnexpectedMsg = new9pError("unexpected message") // returned when an unexpected message is encountered
41 4b33cdd0 2015-11-30 stephen.d ErrWalkLimit = new9pError("too many wnames in walk")
42 4b33cdd0 2015-11-30 stephen.d ErrClosed = errors.New("closed")
43 4b33cdd0 2015-11-30 stephen.d )
44 4b33cdd0 2015-11-30 stephen.d
45 4b33cdd0 2015-11-30 stephen.d // new9pError returns a new 9p error ready for the wire.
46 4b33cdd0 2015-11-30 stephen.d func new9pError(s string) error {
47 4b33cdd0 2015-11-30 stephen.d return MessageRerror{Ename: s}
48 4b33cdd0 2015-11-30 stephen.d }
49 4b33cdd0 2015-11-30 stephen.d
50 a0568195 2016-05-23 stevvooe // Type ensures that 9p errors can be transparently used as a 9p message in an
51 a0568195 2016-05-23 stevvooe // Fcall.
52 4b33cdd0 2015-11-30 stephen.d func (MessageRerror) Type() FcallType {
53 4b33cdd0 2015-11-30 stephen.d return Rerror
54 4b33cdd0 2015-11-30 stephen.d }
55 4b33cdd0 2015-11-30 stephen.d
56 4b33cdd0 2015-11-30 stephen.d func (e MessageRerror) Error() string {
57 4b33cdd0 2015-11-30 stephen.d return fmt.Sprintf("9p: %v", e.Ename)
58 4b33cdd0 2015-11-30 stephen.d }