-
Notifications
You must be signed in to change notification settings - Fork 49
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
Fixed to use apierror.APIError instead of spanner.Error #90
Fixed to use apierror.APIError instead of spanner.Error #90
Conversation
Sorry for the late reply and thank you for the contribution. I didn't notice the spanner.Error's code will be deprecated. The spanner library depends on spanner.Error type before so I wrapped an error inside yo by spanner.Error. The spanner.Error's Code is deprecated in favor of spanner.ErrCode(). It means the code is retrieved from error by status.FromError() as the common way for gRPC. btw if we can use other error type, I think we don't need to apierror.APIError. We can just implement an interface for status.FromError() for an error. Is there a reason or a library that uses apierror.APIError instead of spanner.Error? |
Ah ignore me. I read the comment in spanner.Error. |
Thanks for getting back to me! I noticed the deprecation of spanner.Error when a file output by Yo failed the latest staticcheck check. So, not being familiar with the background of this, I looked into the discussion and found that it was fixed in the following pull request. refactor(spanner): return APIError as wrapped error in spanner.Error struct In the review comments in the above PR, I found the following statement.
It may be difficult to determine from this information alone, but I hope it is helpful. |
templates/yo_db.go.tpl
Outdated
return status.Convert(se.Unwrap()) | ||
var ae *apierror.APIError | ||
if errors.As(e.err, &ae) { | ||
return status.Convert(ae.Unwrap()) |
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.
apierror.APIError implements GRPCStatus() so it is enough to just call status.Convert(ae)
without unwrap. (not sure why we use unwrap for spanner.Error)
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.
Thank you for pointing this out. I have corrected the issue in 464537e .
sorry for so late again. I checked the implementations. I have a concern in the proposed implementation. if a user of Yo uses old spanner library that hasn't introduced apierrors.Error, it makes an unexpected behavior. apierrors.Error was introduced since cloud.google.com/go/spanner v1.28.0. It is about 4 months ago. So the issue may not happen. I leave a comment but LGTM. |
Thanks for your review and comments! I have removed the unnecessary Unwrap implementation that you pointed out in your review. I apologize for the inconvenience and I would be happy to review it again. Thank you so much. |
Thank you for your contribution! |
@kazegusuri If a release is planned, I would appreciate it if you could let me know when it will be available. Thank you for your cooperation! |
@yukia3e sorry. 🙏 I just released a new version. |
Thank you, I'm glad I could contribute to yo! |
Dear Developers.
I noticed that Yo is using DEPRECATED spanner.Error.
So I have modified it to use APIError.APIError, as exemplified in the spanner package.
ref. https://pkg.go.dev/cloud.google.com/go/spanner#Error
I also re-created various templates with the modified contents in the Docker image environment specified in
.circleci/config.yml
.This is my first contribution to Yo. So I apologize if I skipped any necessary steps.
Thank you in advance for your review.