mirror of
https://github.com/ipfs/kubo.git
synced 2025-06-22 04:09:04 +08:00
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>
This commit is contained in:

committed by
Juan Batiz-Benet

parent
ca2828f33c
commit
ef0826acd6
@ -103,11 +103,12 @@ func (c *Command) Call(req Request) Response {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
// if returned error is a commands.Error, use its error code
|
// if returned error is a commands.Error, use its error code
|
||||||
// otherwise, just default the code to ErrNormal
|
// otherwise, just default the code to ErrNormal
|
||||||
var e Error
|
switch e := err.(type) {
|
||||||
e, ok := err.(Error)
|
case *Error:
|
||||||
if ok {
|
|
||||||
res.SetError(e, e.Code)
|
res.SetError(e, e.Code)
|
||||||
} else {
|
case Error:
|
||||||
|
res.SetError(e, e.Code)
|
||||||
|
default:
|
||||||
res.SetError(err, ErrNormal)
|
res.SetError(err, ErrNormal)
|
||||||
}
|
}
|
||||||
return res
|
return res
|
||||||
|
Reference in New Issue
Block a user