summaryrefslogtreecommitdiffstats
path: root/api/vppapi_errors.go
diff options
context:
space:
mode:
authorOndrej Fabry <ofabry@cisco.com>2018-08-22 06:07:04 +0200
committerOndrej Fabry <ofabry@cisco.com>2018-08-22 06:07:04 +0200
commit892683bef86cacc2ccda2b4df2b079171bd92164 (patch)
treebb27f2abca3b1998ac808874d4759ff81b9c83dc /api/vppapi_errors.go
parent08ddeac03fd3832d44a3dfb48ee85ecd95d2b388 (diff)
Show VPPApiError value always and remove RegisterBinAPITypes for mock adapter
Change-Id: I3b216748df1a372f25cc94e3df5d7b1b2b7a8a40 Signed-off-by: Ondrej Fabry <ofabry@cisco.com>
Diffstat (limited to 'api/vppapi_errors.go')
-rw-r--r--api/vppapi_errors.go14
1 files changed, 12 insertions, 2 deletions
diff --git a/api/vppapi_errors.go b/api/vppapi_errors.go
index c921e14..18ab87f 100644
--- a/api/vppapi_errors.go
+++ b/api/vppapi_errors.go
@@ -5,16 +5,26 @@ import (
"strconv"
)
+// RetvalToVPPApiError returns error for retval value.
+// Retval 0 returns nil error.
+func RetvalToVPPApiError(retval int32) error {
+ if retval == 0 {
+ return nil
+ }
+ return VPPApiError(retval)
+}
+
// VPPApiError represents VPP's vnet API error that is usually
// returned as Retval field in replies from VPP binary API.
type VPPApiError int32
func (e VPPApiError) Error() string {
+ errid := int64(e)
var errstr string
if s, ok := vppApiErrors[e]; ok {
- errstr = s
+ errstr = fmt.Sprintf("%s (%d)", s, errid)
} else {
- errstr = strconv.Itoa(int(e))
+ errstr = strconv.FormatInt(errid, 10)
}
return fmt.Sprintf("VPPApiError: %s", errstr)
}