From e00a6475040dfc05e80223630ac0fac8d9a4c2d3 Mon Sep 17 00:00:00 2001 From: Ghe Rivero Date: Thu, 16 Mar 2017 23:46:09 +0100 Subject: [PATCH] Return type.Error instead of plain error This way, we can use Error.Code attribute to check error type without needing to regexp the message string --- pkg/invoke/raw_exec.go | 8 ++------ pkg/types/types.go | 6 +++++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/invoke/raw_exec.go b/pkg/invoke/raw_exec.go index d1bd860d..93f1e75d 100644 --- a/pkg/invoke/raw_exec.go +++ b/pkg/invoke/raw_exec.go @@ -50,13 +50,9 @@ func pluginErr(err error, output []byte) error { if _, ok := err.(*exec.ExitError); ok { emsg := types.Error{} if perr := json.Unmarshal(output, &emsg); perr != nil { - return fmt.Errorf("netplugin failed but error parsing its diagnostic message %q: %v", string(output), perr) + emsg.Msg = fmt.Sprintf("netplugin failed but error parsing its diagnostic message %q: %v", string(output), perr) } - details := "" - if emsg.Details != "" { - details = fmt.Sprintf("; %v", emsg.Details) - } - return fmt.Errorf("%v%v", emsg.Msg, details) + return &emsg } return err diff --git a/pkg/types/types.go b/pkg/types/types.go index 3263015a..64127560 100644 --- a/pkg/types/types.go +++ b/pkg/types/types.go @@ -136,7 +136,11 @@ type Error struct { } func (e *Error) Error() string { - return e.Msg + details := "" + if e.Details != "" { + details = fmt.Sprintf("; %v", e.Details) + } + return fmt.Sprintf("%v%v", e.Msg, details) } func (e *Error) Print() error {