From ef0826acd621a65be8ccb4cb1977b83d1b615e4d Mon Sep 17 00:00:00 2001
From: Brian Tiger Chow <brian.holderchow@gmail.com>
Date: Thu, 13 Nov 2014 03:43:07 -0800
Subject: [PATCH] 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>
---
 commands/command.go | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/commands/command.go b/commands/command.go
index 5e031338e..383e9f217 100644
--- a/commands/command.go
+++ b/commands/command.go
@@ -103,11 +103,12 @@ func (c *Command) Call(req Request) Response {
 	if err != nil {
 		// if returned error is a commands.Error, use its error code
 		// otherwise, just default the code to ErrNormal
-		var e Error
-		e, ok := err.(Error)
-		if ok {
+		switch e := err.(type) {
+		case *Error:
 			res.SetError(e, e.Code)
-		} else {
+		case Error:
+			res.SetError(e, e.Code)
+		default:
 			res.SetError(err, ErrNormal)
 		}
 		return res
-- 
GitLab