Repository navigation
fix(errkit): classify errkit errors that have no kind - #829
Open
Conversation
IsKind and GetErrorKind classify an error from its cause only when the parsed error has no kind, which they check as a nil kind. But parseError merged a wrapped *ErrorX's kind unconditionally, and CombineErrKinds returns an empty, non-nil kind when neither error has one. So an errkit error, or an error wrapping one, always looked classified: IsKind returned false for a "no such host" error built with errkit.New or errkit.Wrap, and GetErrorKind returned an empty kind instead of falling back to ErrKindUnknown. Only Kind() treated an empty kind as no kind. Define that rule once in hasKind and have parseError never store an empty kind, so a parsed error keeps a nil kind when there is none. Kind() uses the same rule, and MarshalJSON reports Kind() instead of repeating its fallback. errkit errors without a kind now classify the way plain errors with the same cause do. Callers that branch on the kind see the difference: retryablehttp-go stops retrying a request whose errkit error has a permanent network cause, and nuclei's host error cache skips the host as permanently unresponsive. For errors that match no kind, GetErrorKind and MarshalJSON report unknown-error instead of "", so nuclei's error log shows unknown-error for them again (#826), and ToSlogAttrs leaves the kind out, as it does for plain errors. Fixes: #827 Signed-off-by: Dwi Siswanto <git@dw1.io>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
IsKind and GetErrorKind classify an error from its cause only when
the parsed error has no kind, which they check as a nil kind. But
parseError merged a wrapped *ErrorX's kind unconditionally, and
CombineErrKinds returns an empty, non-nil kind when neither error has
one. So an errkit error, or an error wrapping one, always looked
classified: IsKind returned false for a "no such host" error built
with errkit.New or errkit.Wrap, and GetErrorKind returned an empty
kind instead of falling back to ErrKindUnknown. Only Kind() treated an
empty kind as no kind.
Define that rule once in hasKind and have parseError never store an
empty kind, so a parsed error keeps a nil kind when there is none.
Kind() uses the same rule, and MarshalJSON reports Kind() instead of
repeating its fallback.
errkit errors without a kind now classify the way plain errors with
the same cause do. Callers that branch on the kind see the
difference: retryablehttp-go stops retrying a request whose errkit
error has a permanent network cause, and nuclei's host error cache
skips the host as permanently unresponsive. For errors that match no
kind, GetErrorKind and MarshalJSON report unknown-error instead of
"", so nuclei's error log shows unknown-error for them again (#826),
and ToSlogAttrs leaves the kind out, as it does for plain errors.
Fixes: #827