8000 Fixes panic in UnwrapError by larsve · Pull Request #5 · modfin/eal · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixes panic in UnwrapError #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 17, 2023
Merged

Fixes panic in UnwrapError #5

merged 2 commits into from
Mar 17, 2023

Conversation

larsve
Copy link
Collaborator
@larsve larsve commented Mar 17, 2023

If an error were passed to eal.UnwrapError that wasn't hashable/comparable, a panic were raised when we tried to use it as a map key. Now we check in UnwrapError if the error is comparable before we try to use it as a map key.

If one tries to call RegisterErrorLogFunc with an error that isn't comparable we'll still raise a panic since until we can log those, there is no point to call RegisterErrorLogFunc, and that will in most cases happen when initializing the program.

The only workaround currently is to either ignore log augmentation for those errors, or change the type to use pointer-receivers to force the creation of those errors to return a pointer to the un-comparable error struct.

This commit also fixes some comments and another bug in the internal esl.errorLogger where the "jwt_text" log field contained the error bitfield and not the jwt.ValidationError text.

If an error were passed to eal.UnwrapError that wasn't hashable/comparable, a
panic were raised when we tried to use it as a map key. Now we check in
UnwrapError if the error is comparable before we try to use it as a map key.

If one tries to call RegisterErrorLogFunc with an error that isn't comparable
we'll still raise a panic since until we can log those, there is no point to
call RegisterErrorLogFunc, and that will in most cases happen when initializing
the program.

The only workaround currently is to either ignore log augmentation for those
errors, or change the type to use pointer-receivers to force the creation of
those errors to return a pointer to the un-comparable error struct.

This commit also fixes some comments and another bug in the internal
esl.errorLogger where the "jwt_text" log field contained the error bitfield
and not the jwt.ValidationError text.
@larsve larsve requested a review from joeledstrom March 17, 2023 11:05
error_test.go Outdated
want: map[string]interface{}{"error_message": "testErr", "registeredErrorLogFunctions": true, "set_log_fields": true, "temporary": false, "type_*eal.testErr": true},
},
{
name: "ApiError-pointer",
Copy link
Contributor
@joeledstrom joeledstrom Mar 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename test to nonComparableError-pointer or similar

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, good catch, I missed that when I re-created a minimal error struct that isn't hashable/comparable. I'll fix both occurrences.

error_test.go Outdated
want: map[string]interface{}{"error_message": "test,lines", "registeredErrorLogFunctions": true, "type_*eal.nonComparableError": true},
},
{
name: "ApiError-struct",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Copy link
Contributor
@joeledstrom joeledstrom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@larsve larsve merged commit d24d4b1 into master Mar 17, 2023
@larsve larsve deleted the bug/panic_in_UnwrapError branch March 17, 2023 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0