Sanitize go-github ErrorResponse to prevent panic in SDK error handling#629
Merged
Sanitize go-github ErrorResponse to prevent panic in SDK error handling#629
Conversation
…K typed nil errors.Is interaction
strips *github.ErrorResponse from the error chain before it reaches the SDK
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.
Summary
Fixes a nil pointer dereference panic caused by the interaction between go-github v81's
ErrorResponse.Isand the SDK'sguessErrorStatusfunction.go-github v76 (bumped from v72 to v81 in #574) changed
ErrorResponse.Isfrom a simple type assertionto calling
errors.As(target, &v)on the target. See PR: google/go-github#3739The SDK's
guessErrorStatus(
backend/status.go:112) passes typed nil targets ((*url.Error)(nil)) toerrors.Is.When
errors.Iswalks the error chain and reaches*github.ErrorResponse, the v81ErrorResponse.Iscallserrors.Ason that typed nil, which tries to callUnwrap()onthe nil receiver — causing a nil pointer dereference panic.
The fix adds
sanitizeGitHubErrorwhich converts*github.ErrorResponseto a plain errorat the
addErrorSourceToErrorboundary, preserving the error message while stripping theproblematic
Ismethod from the error chain.Manual reproduction steps
grafana, Repository tothis-repo-does-not-existpanic triggered error="runtime error: invalid memory address or nil pointer dereference"With this fix applied, the query returns a proper error response instead of panicking.
Fixes https://github.com/grafana/oss-big-tent-squad/issues/183