Harden validation, optimize encoding, and add test coverage#3
Merged
VojtechVitek merged 14 commits intomasterfrom Mar 24, 2026
Merged
Harden validation, optimize encoding, and add test coverage#3VojtechVitek merged 14 commits intomasterfrom
VojtechVitek merged 14 commits intomasterfrom
Conversation
MarshalText now errors on zero-value UUID instead of producing an unparseable "prefix_000..." string. Scan validates that the scanned UUID is version 7, matching the constraint enforced by ParseUUID.
VojtechVitek
approved these changes
Mar 24, 2026
| } | ||
| if v > 7 { | ||
| return [16]byte{}, fmt.Errorf("typeid: base32 overflow at pos 0") | ||
| return [16]byte{}, ErrOverflowBase32 |
Contributor
There was a problem hiding this comment.
I'm not sure if we want to export this error type / expose it to the pkg API.
Is there a reason why devs would need to know this exact sentinel error?
| func Int64From[P Prefixer](v int64) (Int64[P], error) { | ||
| if v < 0 { | ||
| return Int64[P]{}, ErrNegativeInt | ||
| if v <= 0 { |
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
MarshalText,Value, andScan; fixUUID.Scanto handle raw 16-byte[]bytefrom binary SQL drivers (e.g. pgx)String/MarshalTextdown from 2 allocs to 1, ~30% fasterfmt.Errorf, tightensplitTypeid, drop redundantErrNegativeIntBreaking changes
Int64From(0)now returnsErrNonPositiveInt(previously succeeded but produced an unusable ID)ErrNegativeIntremoved, replaced byErrNonPositiveIntBenchmarks
Test plan
go test ./...passesgo test -bench=. -benchmemshows 1 alloc on encode, 0 on decode