Skip to content

Commit 8706809

Browse files
committed
Use a consistent format for errors
1 parent c14e1c9 commit 8706809

10 files changed

+34
-34
lines changed

auth.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (conn *Conn) Auth(methods []Auth) error {
7272
return err
7373
}
7474
if len(s) < 2 || !bytes.Equal(s[0], []byte("REJECTED")) {
75-
return errors.New("authentication protocol error")
75+
return errors.New("dbus: authentication protocol error")
7676
}
7777
s = s[1:]
7878
for _, v := range s {
@@ -89,7 +89,7 @@ func (conn *Conn) Auth(methods []Auth) error {
8989
case AuthContinue:
9090
err, ok = conn.tryAuth(m, waitingForData, in)
9191
default:
92-
panic("invalid authentication status")
92+
panic("dbus: invalid authentication status")
9393
}
9494
if err != nil {
9595
return err
@@ -110,7 +110,7 @@ func (conn *Conn) Auth(methods []Auth) error {
110110
conn.unixFD = true
111111
case bytes.Equal(line[0], []byte("ERROR")):
112112
default:
113-
return errors.New("authentication protocol error")
113+
return errors.New("dbus: authentication protocol error")
114114
}
115115
}
116116
err = authWriteLine(conn.transport, []byte("BEGIN"))
@@ -125,7 +125,7 @@ func (conn *Conn) Auth(methods []Auth) error {
125125
}
126126
}
127127
}
128-
return errors.New("authentication failed")
128+
return errors.New("dbus: authentication failed")
129129
}
130130

131131
// tryAuth tries to authenticate with m as the mechanism, using state as the
@@ -216,9 +216,9 @@ func (conn *Conn) tryAuth(m Auth, state authState, in *bufio.Reader) (error, boo
216216
case state == waitingForReject && string(s[0]) == "REJECTED":
217217
return nil, false
218218
case state == waitingForReject:
219-
return errors.New("authentication protocol error"), false
219+
return errors.New("dbus: authentication protocol error"), false
220220
default:
221-
panic("invalid auth state")
221+
panic("dbus: invalid auth state")
222222
}
223223
}
224224
}

call.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type Call struct {
2424
Body []interface{}
2525
}
2626

27-
var errSignature = errors.New("mismatched signature")
27+
var errSignature = errors.New("dbus: mismatched signature")
2828

2929
// Store stores the body of the reply into the provided pointers. It returns
3030
// an error if the signatures of the body and retvalues don't match, or if
@@ -85,7 +85,7 @@ func (o *Object) Go(method string, flags Flags, ch chan *Call, args ...interface
8585
if ch == nil {
8686
ch = make(chan *Call, 10)
8787
} else if cap(ch) == 0 {
88-
panic("(*dbus.Object).Go: unbuffered channel")
88+
panic("dbus: unbuffered channel passed to (*Object).Go")
8989
}
9090
call := &Call{
9191
Destination: o.dest,

conn.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ var (
2121
)
2222

2323
// ErrClosed is the error returned by calls on a closed connection.
24-
var ErrClosed = errors.New("closed by user")
24+
var ErrClosed = errors.New("dbus: connection closed by user")
2525

2626
// Conn represents a connection to a message bus (usually, the system or
2727
// session bus).
@@ -101,7 +101,7 @@ func SessionBusPrivate() (*Conn, error) {
101101
i := bytes.IndexByte(b, '=')
102102
j := bytes.IndexByte(b, '\n')
103103
if i == -1 || j == -1 {
104-
return nil, errors.New("couldn't determine address of the session bus")
104+
return nil, errors.New("dbus: couldn't determine address of session bus")
105105
}
106106
return Dial(string(b[i+1 : j]))
107107
}
@@ -383,7 +383,7 @@ func (conn *Conn) Send(msg *Message, ch chan *Call) *Call {
383383
if ch == nil {
384384
ch = make(chan *Call, 5)
385385
} else if cap(ch) == 0 {
386-
panic("(*dbus.Conn).Send: unbuffered channel")
386+
panic("dbus: unbuffered channel passed to (*Conn).Send")
387387
}
388388
call = new(Call)
389389
call.Destination, _ = msg.Headers[FieldDestination].value.(string)
@@ -558,12 +558,12 @@ func getTransport(address string) (transport, error) {
558558
for _, v := range addresses {
559559
i := strings.IndexRune(v, ':')
560560
if i == -1 {
561-
err = errors.New("bad address: no transport")
561+
err = errors.New("dbus: invalid bus address (no transport)")
562562
continue
563563
}
564564
f := m[v[:i]]
565565
if f == nil {
566-
err = errors.New("bad address: invalid or unsupported transport")
566+
err = errors.New("dbus: invalid bus address (invalid or unsupported transport)")
567567
}
568568
t, err = f(v[i+1:])
569569
if err == nil {

dbus.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ type InvalidTypeError struct {
3232
Type reflect.Type
3333
}
3434

35-
func (err InvalidTypeError) Error() string {
36-
return "dbus: invalid type " + err.Type.String()
35+
func (e InvalidTypeError) Error() string {
36+
return "dbus: invalid type " + e.Type.String()
3737
}
3838

3939
// Store copies the values contained in src to dest, which must be a slice of

decoder.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (dec *Decoder) Decode(vs ...interface{}) (err error) {
6161
var ok bool
6262
if err, ok = recover().(error); ok {
6363
if err == io.EOF || err == io.ErrUnexpectedEOF {
64-
err = FormatError("input too short (unexpected EOF)")
64+
err = FormatError("unexpected EOF")
6565
}
6666
}
6767
}()
@@ -261,5 +261,5 @@ func (dec *Decoder) decode(v reflect.Value, depth int) {
261261
type FormatError string
262262

263263
func (e FormatError) Error() string {
264-
return "dbus format error: " + string(e)
264+
return "dbus: wire format error: " + string(e)
265265
}

export.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,19 +139,19 @@ func (conn *Conn) handleCall(msg *Message) {
139139
// formatted as "interface.member", e.g., "org.freedesktop.DBus.NameLost".
140140
func (conn *Conn) Emit(path ObjectPath, name string, values ...interface{}) error {
141141
if !path.IsValid() {
142-
return errors.New("invalid object path")
142+
return errors.New("dbus: invalid object path")
143143
}
144144
i := strings.LastIndex(name, ".")
145145
if i == -1 {
146-
return errors.New("invalid method name")
146+
return errors.New("dbus: invalid method name")
147147
}
148148
iface := name[:i]
149149
member := name[i+1:]
150150
if !isValidMember(member) {
151-
return errors.New("invalid method name")
151+
return errors.New("dbus: invalid method name")
152152
}
153153
if !isValidInterface(iface) {
154-
return errors.New("invalid interface name")
154+
return errors.New("dbus: invalid interface name")
155155
}
156156
msg := new(Message)
157157
msg.Type = TypeSignal
@@ -191,7 +191,7 @@ func (conn *Conn) Emit(path ObjectPath, name string, values ...interface{}) erro
191191
// Export returns an error if path is not a valid path name.
192192
func (conn *Conn) Export(v interface{}, path ObjectPath, iface string) error {
193193
if !path.IsValid() {
194-
return errors.New("invalid path name")
194+
return errors.New("dbus: invalid path name")
195195
}
196196
conn.handlersLck.Lock()
197197
if _, ok := conn.handlers[path]; !ok {

message.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const (
5858
type InvalidMessageError string
5959

6060
func (e InvalidMessageError) Error() string {
61-
return "invalid message: " + string(e)
61+
return "dbus: invalid message: " + string(e)
6262
}
6363

6464
// fieldType are the types of the various header fields.

sig.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package dbus
22

33
import (
4+
"fmt"
45
"reflect"
56
"strings"
67
)
@@ -168,8 +169,8 @@ type SignatureError struct {
168169
Reason string
169170
}
170171

171-
func (err SignatureError) Error() string {
172-
return "dbus: invalid signature: '" + err.Sig + "' (" + err.Reason + ")"
172+
func (e SignatureError) Error() string {
173+
return fmt.Sprintf("dbus: invalid signature: %q (%s)", e.Sig, e.Reason)
173174
}
174175

175176
// Try to read a single type from this string. If it was successfull, err is nil

transport_generic.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (t genericTransport) ReadMessage() (*Message, error) {
2828
func (t genericTransport) SendMessage(msg *Message) error {
2929
for _, v := range msg.Body {
3030
if _, ok := v.(UnixFD); ok {
31-
return errors.New("unix fd passing not enabled")
31+
return errors.New("dbus: unix fd passing not enabled")
3232
}
3333
}
3434
return msg.EncodeTo(t, binary.LittleEndian)

transport_unix.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func (o *oobReader) Read(b []byte) (n int, err error) {
2222
return n, err
2323
}
2424
if flags&syscall.MSG_CTRUNC != 0 {
25-
return n, errors.New("control data truncated (too many fds received)")
25+
return n, errors.New("dbus: control data truncated (too many fds received)")
2626
}
2727
o.oob = append(o.oob, o.buf[:oobn]...)
2828
return n, nil
@@ -41,7 +41,7 @@ func newUnixTransport(keys string) (transport, error) {
4141
path := getKey(keys, "path")
4242
switch {
4343
case abstract == "" && path == "":
44-
return nil, errors.New("bad address: neither path nor abstract set")
44+
return nil, errors.New("dbus: invalid address (neither path nor abstract set)")
4545
case abstract != "" && path == "":
4646
t.UnixConn, err = net.DialUnix("unix", nil, &net.UnixAddr{Name: "@" + abstract, Net: "unix"})
4747
if err != nil {
@@ -54,10 +54,9 @@ func newUnixTransport(keys string) (transport, error) {
5454
return nil, err
5555
}
5656
return t, nil
57-
case abstract != "" && path != "":
58-
return nil, errors.New("bad address: both path and abstract set")
57+
default:
58+
return nil, errors.New("dbus: invalid address (both path and abstract set)")
5959
}
60-
panic("not reached")
6160
}
6261

6362
func (t *unixTransport) EnableUnixFDs() {
@@ -121,15 +120,15 @@ func (t *unixTransport) ReadMessage() (*Message, error) {
121120
}
122121
if unixfds != 0 {
123122
if !t.hasUnixFDs {
124-
return nil, errors.New("got unix fds on unsupported transport")
123+
return nil, errors.New("dbus: got unix fds on unsupported transport")
125124
}
126125
// read the fds from the OOB data
127126
scms, err := syscall.ParseSocketControlMessage(rd.oob)
128127
if err != nil {
129128
return nil, err
130129
}
131130
if len(scms) != 1 {
132-
return nil, errors.New("invalid number of SCM's received")
131+
return nil, errors.New("dbus: received more than one socket control message")
133132
}
134133
fds, err := syscall.ParseUnixRights(&scms[0])
135134
if err != nil {
@@ -164,7 +163,7 @@ func (t *unixTransport) SendMessage(msg *Message) error {
164163
}
165164
if len(fds) != 0 {
166165
if !t.hasUnixFDs {
167-
return errors.New("unix fd passing not enabled")
166+
return errors.New("dbus: unix fd passing not enabled")
168167
}
169168
msg.Headers[FieldUnixFDs] = MakeVariant(uint32(len(fds)))
170169
oob := syscall.UnixRights(fds...)

0 commit comments

Comments
 (0)