-
Notifications
You must be signed in to change notification settings - Fork 362
build(deps): migrate to github.com/ccoveille/go-safecast v2 #2685
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
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2685 +/- ##
==========================================
- Coverage 77.02% 76.43% -0.59%
==========================================
Files 462 462
Lines 49072 49095 +23
==========================================
- Hits 37794 37521 -273
- Misses 8497 8812 +315
+ Partials 2781 2762 -19 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
I have a few things so fix apparently. No problem. |
|
I'm unsure how to deal with issues reported by code coverage. As you stated in your comment, many of the values cannot be negative even they were defined as signed integer. go-safecast v2 no longer returns 0 on error, that's why I added this piece of code. Should I ignore the test ? I would prefer not to use safecast.MustConvert that panic if there is a conversion issue. So I'm interested by feedback here. |
We can ignore this. The codecov check isn't mandatory. |
|
@ccoVeille thank you for sending this! Could you run |
d5eb3bb to
7ceb79f
Compare
| uintNumToDrop, _ := safecast.Convert[uint64](numToDrop) | ||
| uintNumToDrop, err := safecast.Convert[uint64](numToDrop) | ||
| if err != nil { | ||
| uintNumToDrop = 0 |
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.
I think it might be a good idea to add a new wrapper method for this in spiceerrors called MustSafecast. Have it take in the generic type, call the safecast here, then if an error occurs, have it call spiceerrors.DebugAssert to fail with a panic at test time (but no-op at prod time) and then return the default value given to the function. That way, we have documented behavior everywhere.
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.
I can see methods like what you describe here in spiceerrors.
So I could implement something, but first, I would like to check things with you guys, at least the maintainers:
- is there anyone else than Josh who wants to do it the way he described?
- do you expect me to do this ?
I'm asking because I'm unsure I'm the right person to update this.
Just in case, my lib has two methods you could consider:
- MustConvert that panics on failure
- RequireConvert that calls t.Error on failure and so invalidate the tests
Here I feel none of these matches what you described.
Also, I don't understand the need to panic on tests and passes on "production"
If the code differs, it cannot be tested with the same way. I dislike the idea.
That said, I can adapt my PR. But it goes a bit too far from what I expected to do on your project as the owner and maintainer of go-safecast.
I created this PR to facilitate the migration from v1 to v2 for you. I didn't plan to invest more.
Please let me know.
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.
We have a general rule of not allowing panics at production time; instead, we prefer to return errors and panic only during tests to identify bugs but not cause production crashes.
We can change the behavior in a follow, I suppose
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.
I would prefer you to apply something that suits your habit instead of having a PR that I have to update possibly iteratively because my changes might not face what you are expecting in term of changes.
Please note that go-safecast Convert method doesn't panics either in v1 or v2
So if you have an issue with the way you use my lib with v2, you had it in v1
7ceb79f to
bb13936
Compare
|
I'm okay with merging this without the aforementioned refactors. We can take that as a follow-on. One thing that isn't currently working is the e2e tests - they're |
bb13936 to
e4d7025
Compare
tstirrat15
left a comment
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. Thank you for putting this up!
Description
I'm the owner and maintainer of ccoVeille/go-safecast
I have just published my v2.0.0
Please take a look at the change I introduced to understand the changes I did in your code.
This is somehow a follow-up of authzed/zed#574
Testing
$ go test -v ./...References