fix(commands/err)
I didn't know there were dragons here. When casting errors we've gotta be careful. Apparently both values and pointers satisfy the error interface. Type checking for one doesn't catch the other. cc @whyrusleeping @mappum @jbenet License: MIT Signed-off-by: Brian Tiger Chow <brian@perfmode.com>
Brian Tiger Chow committed
Nov 13, 2014 at 03:43 UTC
ef0826acd621a65be8ccb4cb1977b83d1b615e4d
1 file changed
+5
-4
commands/command.go
+5
-4
@@ -103,11 +103,12 @@ func (c *Command) Call(req Request) Response {
103
if err != nil {
104
// if returned error is a commands.Error, use its error code
105
// otherwise, just default the code to ErrNormal
106
- var e Error
107
- e, ok := err.(Error)
108
- if ok {
106
+ switch e := err.(type) {
107
+ case *Error:
108
res.SetError(e, e.Code)
110
- } else {
109
+ case Error:
110
+ res.SetError(e, e.Code)
111
+ default:
112
res.SetError(err, ErrNormal)
113
}
114
return res