Skip to content

Commit

Permalink
Add UnmarshalError to handle json unmarshal errors
Browse files Browse the repository at this point in the history
  • Loading branch information
buty4649 committed Apr 18, 2024
1 parent 44910a1 commit 165c9f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iproute2/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions iproute2/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 165c9f2

Please sign in to comment.