From 165c9f2f64077af7ced19260fa420e666e483495 Mon Sep 17 00:00:00 2001 From: buty4649 Date: Thu, 18 Apr 2024 15:57:12 +0900 Subject: [PATCH] Add UnmarshalError to handle json unmarshal errors --- iproute2/base.go | 2 +- iproute2/error.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/iproute2/base.go b/iproute2/base.go index 4d9885f..5ee73ec 100644 --- a/iproute2/base.go +++ b/iproute2/base.go @@ -214,7 +214,7 @@ func unmarshalInterfacesData(data string) (Interfaces, error) { var addresses Interfaces err := json.Unmarshal([]byte(data), &addresses) if err != nil { - return nil, err + return nil, &UnmarshalError{Msg: err.Error(), Content: data} } return addresses, nil diff --git a/iproute2/error.go b/iproute2/error.go index 87ea93e..2e89bb3 100644 --- a/iproute2/error.go +++ b/iproute2/error.go @@ -42,6 +42,15 @@ func (e *OperationNotPermittedError) Error() string { return e.Msg } +type UnmarshalError struct { + Msg string + Content string +} + +func (e *UnmarshalError) Error() string { + return fmt.Sprint(e.Msg, ": ", e.Content) +} + type UnknownError struct { Msg string }