Blame


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