-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.
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", |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
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.