feat: default and catch funcs - #215
Conversation
There was a problem hiding this comment.
Your free trial has ended. If you'd like to continue receiving code reviews, you can add a payment method here.
Deploying zog with
|
| Latest commit: |
9af7101
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f0665d38.zog-3a0.pages.dev |
| Branch Preview URL: | https://feat-catch-and-default-funcs.zog-3a0.pages.dev |
WalkthroughThis pull request refactors default and catch value handling across all schema types (Any, Boolean, Number, String, Time, Map, Slice) from concrete pointers to lazy function-based providers. Core parsing/validation functions are updated to accept and invoke these function callbacks instead of dereferencing values directly. Tests are added for both parsing and validation flows. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@toZSS.go`:
- Around line 397-402: The function defaultValueFromAnyFunc should guard against
the case where defaultFunc returns nil before calling deepCopyPrimitivePtr;
modify defaultValueFromAnyFunc (the function named defaultValueFromAnyFunc) to
check if val == nil (or reflect.ValueOf(val).IsValid()/IsNil for
interface-contained nil) and return nil immediately when the returned interface
is nil, otherwise call deepCopyPrimitivePtr(&val) as before to avoid
deepCopyPrimitivePtr invoking rv.Elem() on an invalid reflect.Value and causing
a panic.
🧹 Nitpick comments (1)
slices.go (1)
214-224:Defaultdelegates toDefaultFunc— note shared reference for mutable types.
Default(val any)closes overval. For reference types like slices, every invocation ofdefaultFuncreturns the same underlying reference. If a Validate/Transform later mutates the slice in-place, the "default" is permanently changed.DefaultFuncgives users an escape hatch (return a fresh slice each call), butDefaultsilently shares.This is a pre-existing concern (same semantics as the old pointer-based approach) and not a regression, but worth a doc note or comment for future maintainers.
Summary by CodeRabbit
Release Notes
New Features
DefaultFunc()andCatchFunc()methods across all schema types, enabling defaults and catch values to be supplied via functions for dynamic value generation.Documentation
DefaultFunc()andCatchFunc()methods.