-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Return subfields in unpack error (#313)
* Return subfield IDs upon unpack error * Tidy test * Comments * Make linter happy * Remove FieldIDs
- Loading branch information
Showing
6 changed files
with
314 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
) | ||
|
||
// UnpackError returns an error with the possibility to access the RawMessage when | ||
// the connection failed to unpack the message | ||
type UnpackError struct { | ||
Err error | ||
FieldID string | ||
RawMessage []byte | ||
} | ||
|
||
func (e *UnpackError) Error() string { | ||
return e.Err.Error() | ||
} | ||
|
||
func (e *UnpackError) Unwrap() error { | ||
return e.Err | ||
} | ||
|
||
// FieldIDs returns the list of field and subfield IDs (if any) that errored from outermost inwards | ||
func (e *UnpackError) FieldIDs() []string { | ||
fieldIDs := []string{e.FieldID} | ||
err := e.Err | ||
var unpackError *UnpackError | ||
for { | ||
if errors.As(err, &unpackError) { | ||
fieldIDs = append(fieldIDs, unpackError.FieldID) | ||
err = unpackError.Unwrap() | ||
} else { | ||
break | ||
} | ||
} | ||
|
||
return fieldIDs | ||
} | ||
|
||
type PackError struct { | ||
Err error | ||
} | ||
|
||
func (e *PackError) Error() string { | ||
return e.Err.Error() | ||
} | ||
|
||
func (e *PackError) Unwrap() error { | ||
return e.Err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.