Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changes/20250807151301.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:sparkles: `commonerrors` Add ErrFailed
5 changes: 4 additions & 1 deletion utils/commonerrors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ var (
ErrEOF = errors.New("end of file")
ErrMalicious = errors.New("suspected malicious intent")
ErrOutOfRange = errors.New("out of range")
ErrFailed = errors.New("failed")
// ErrWarning is a generic error that can be used when an error should be raised but it shouldn't necessary be
// passed up the chain, for example in cases where an error should be logged but the program should continue. In
// these situations it should be handled immediately and then ignored/set to nil.
Expand All @@ -57,7 +58,7 @@ var warningStrPrepend = fmt.Sprintf("%v: ", warningStr)

// IsCommonError returns whether an error is a commonerror
func IsCommonError(target error) bool {
return Any(target, ErrNotImplemented, ErrNoExtension, ErrNoLogger, ErrNoLoggerSource, ErrNoLogSource, ErrUndefined, ErrInvalidDestination, ErrTimeout, ErrLocked, ErrStaleLock, ErrExists, ErrNotFound, ErrUnsupported, ErrUnavailable, ErrWrongUser, ErrUnauthorised, ErrUnknown, ErrInvalid, ErrConflict, ErrMarshalling, ErrCancelled, ErrEmpty, ErrUnexpected, ErrTooLarge, ErrForbidden, ErrCondition, ErrEOF, ErrMalicious, ErrWarning, ErrOutOfRange)
return Any(target, ErrNotImplemented, ErrNoExtension, ErrNoLogger, ErrNoLoggerSource, ErrNoLogSource, ErrUndefined, ErrInvalidDestination, ErrTimeout, ErrLocked, ErrStaleLock, ErrExists, ErrNotFound, ErrUnsupported, ErrUnavailable, ErrWrongUser, ErrUnauthorised, ErrUnknown, ErrInvalid, ErrConflict, ErrMarshalling, ErrCancelled, ErrEmpty, ErrUnexpected, ErrTooLarge, ErrForbidden, ErrCondition, ErrEOF, ErrMalicious, ErrWarning, ErrOutOfRange, ErrFailed)
}

// Any determines whether the target error is of the same type as any of the errors `err`
Expand Down Expand Up @@ -183,6 +184,8 @@ func deserialiseCommonError(errStr string) (bool, error) {
return true, ErrWarning
case CorrespondTo(ErrOutOfRange, errStr):
return true, ErrOutOfRange
case CorrespondTo(ErrFailed, errStr):
return true, ErrFailed
}
return false, ErrUnknown
}
Expand Down
1 change: 1 addition & 0 deletions utils/commonerrors/errors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ func TestIsCommonError(t *testing.T) {
ErrMalicious,
ErrWarning,
ErrOutOfRange,
ErrFailed,
}
for i := range commonErrors {
assert.True(t, IsCommonError(commonErrors[i]))
Expand Down
Loading