Skip to content

Conversation

@ccoVeille
Copy link
Contributor

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

@ccoVeille ccoVeille requested a review from a team as a code owner November 4, 2025 00:38
@github-actions github-actions bot added area/cli Affects the command line area/schema Affects the Schema Language area/api v1 Affects the v1 API area/datastore Affects the storage system area/dependencies Affects dependencies area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools) area/dispatch Affects dispatching of requests labels Nov 4, 2025
@codecov
Copy link

codecov bot commented Nov 4, 2025

Codecov Report

❌ Patch coverage is 52.27273% with 21 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.43%. Comparing base (dcdd22b) to head (e4d7025).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/datastore/crdb/pool/pool.go 33.34% 2 Missing and 2 partials ⚠️
pkg/composableschemadsl/compiler/translator.go 33.34% 2 Missing and 2 partials ⚠️
pkg/schemadsl/compiler/translator.go 33.34% 2 Missing and 2 partials ⚠️
internal/datastore/proxy/proxy_test/mock.go 0.00% 3 Missing ⚠️
internal/datastore/postgres/snapshot.go 33.34% 1 Missing and 1 partial ⚠️
internal/developmentmembership/onrset.go 33.34% 1 Missing and 1 partial ⚠️
pkg/cache/cache.go 33.34% 1 Missing and 1 partial ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ccoVeille
Copy link
Contributor Author

I have a few things so fix apparently. No problem.

@ccoVeille
Copy link
Contributor Author

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.

@miparnisari
Copy link
Contributor

I'm unsure how to deal with issues reported by code coverage.

We can ignore this. The codecov check isn't mandatory.

@miparnisari
Copy link
Contributor

@ccoVeille thank you for sending this! Could you run go mod tidy and mage lint:all?

uintNumToDrop, _ := safecast.Convert[uint64](numToDrop)
uintNumToDrop, err := safecast.Convert[uint64](numToDrop)
if err != nil {
uintNumToDrop = 0
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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

@tstirrat15
Copy link
Contributor

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 go.worked to the parent module and they need some updates as well. Is that something that you have time for? Otherwise I can pick this up and keep it moving.

Copy link
Contributor

@tstirrat15 tstirrat15 left a 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!

@tstirrat15 tstirrat15 added this pull request to the merge queue Nov 19, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 19, 2025
@tstirrat15 tstirrat15 added this pull request to the merge queue Nov 19, 2025
Merged via the queue into authzed:main with commit 3370198 Nov 19, 2025
44 of 45 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 19, 2025
@ccoVeille ccoVeille deleted the safecast-v2 branch November 19, 2025 15:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area/api v1 Affects the v1 API area/cli Affects the command line area/datastore Affects the storage system area/dependencies Affects dependencies area/dispatch Affects dispatching of requests area/schema Affects the Schema Language area/tooling Affects the dev or user toolchain (e.g. tests, ci, build tools)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants