Skip to content
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

APIError.Error() nil pointer exception in some cases. #350

Closed
hime opened this issue May 28, 2024 · 3 comments · Fixed by #351
Closed

APIError.Error() nil pointer exception in some cases. #350

hime opened this issue May 28, 2024 · 3 comments · Fixed by #351
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.

Comments

@hime
Copy link

hime commented May 28, 2024

I'm curious if getting a nil pointer exception when trying to get string version of APIError (using .Error()) documented. The issue arises when we attempt to run operations on the wrapped error field APIError.err. We are able to safely created using the ParseError. However, when we call .Error() method on this error, we call APIError.err.Error() without checking if err field was set.

Environment details

  • Package version: gax-go/v2 v2.12.3

Steps to reproduce

  1. Create API Error using ParseError
  2. Call (APIError).Error() on error.

Making sure to follow these steps will guarantee the quickest resolution possible.

Thanks!

@hime hime added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels May 28, 2024
@quartzmo quartzmo self-assigned this May 29, 2024
@quartzmo quartzmo added type: question Request for information or clarification. Not an issue. needs more info This issue needs more information from the customer to proceed. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels May 29, 2024
@quartzmo
Copy link
Member

Hi @hime,

Please provide a complete code example reproducing the issue you encountered, along with the expected output when running your example. Thanks!

@hime
Copy link
Author

hime commented May 29, 2024

Hi @quartzmo,

Here's a code example. Regarding the expected output, maybe we can leave the message unset if error is nil.

Code

// You can edit this code!
// Click here and start typing
package main

import (
	"fmt"

	"github.com/googleapis/gax-go/v2/apierror"
	"google.golang.org/grpc/status"
)

func main() {
	err := status.New(500, "internal error").Err()
	apiErr, _ := apierror.ParseError(err, false)
	fmt.Println("Our error: ", apiErr.Error())
}

Output

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x79e415]

goroutine 1 [running]:
github.com/googleapis/gax-go/v2/apierror.(*APIError).Error(0xc0001ae090)
   .../vendor/github.com/googleapis/gax-go/v2/apierror/apierror.go:210 +0x35
main.main()
   .../example.go:16 +0xd3
exit status 2

@quartzmo
Copy link
Member

@hime Thanks for the quick reply. I reproduced the issue using your code example. I need to do some investigation into what the expected behavior is when the second wrap argument to ParseError is false. Thank you very much for reporting this bug.

@quartzmo quartzmo added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. and removed type: question Request for information or clarification. Not an issue. needs more info This issue needs more information from the customer to proceed. labels May 29, 2024
quartzmo added a commit to quartzmo/gax-go that referenced this issue May 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants