Skip to content

feat: better panic message when user passes non pointer destination to parse/validate functions#205

Merged
Oudwins merged 2 commits intomasterfrom
feat/better-invalid-arg-panic-message
Dec 14, 2025
Merged

feat: better panic message when user passes non pointer destination to parse/validate functions#205
Oudwins merged 2 commits intomasterfrom
feat/better-invalid-arg-panic-message

Conversation

@Oudwins
Copy link
Owner

@Oudwins Oudwins commented Dec 14, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Stricter validation for pointer-style arguments during struct processing to catch invalid inputs earlier.
    • Added a more descriptive runtime error message for invalid argument types to make failures easier to diagnose and debug.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 14, 2025

Walkthrough

Added a new exported panic constant and made struct-pointer handling in StructSchema.process defensive: it now verifies that the provided value is a pointer or interface before dereferencing, panicking with the new constant if the check fails.

Changes

Cohort / File(s) Summary
Panic constant definition
internals/panics.go
Added exported constant PanicInvalidArgumentsExpectedPointer; reformatted existing panic constant declarations.
Struct processing validation
struct.go
StructSchema.process now creates a reflect.Value from ctx.ValPtr, checks that its Kind is Pointer or Interface, and panics with PanicInvalidArgumentsExpectedPointer if not; then obtains the element via Elem().

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Inspect internals/panics.go to ensure the new constant name/message matches project conventions.
  • Review struct.go changes to confirm the reflect.Kind checks are correct for all call sites and that no valid inputs are rejected.
  • Run existing unit tests and add cases where ctx.ValPtr is non-pointer/non-interface to verify the new panic behavior.

Possibly related PRs

Poem

🐰
I nibble through code with careful cheer,
Checking pointers that venture near.
If something’s not a pointer true,
I shout a panic — clear and new!
Hooray for safe derefs, hip-hop-hooray!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: adding a better panic message when users pass non-pointer destinations to parse/validate functions, which aligns with the code changes adding PanicInvalidArgumentsExpectedPointer and defensive pointer validation.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/better-invalid-arg-panic-message

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f8616f and ce7a151.

📒 Files selected for processing (1)
  • struct.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
struct.go (1)
internals/panics.go (2)
  • Panicf (12-14)
  • PanicInvalidArgumentsExpectedPointer (9-9)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
struct.go (1)

152-174: Gap vs PR objective: Validate() path still does raw .Elem() and uses a different panic style.
validate() at Line 153 will still panic with the default reflect panic if a non-pointer is passed, and Line 171 panics via fmt.Sprintf instead of p.Panicf(...). Consider applying the same pointer guard + consistent panic constants here as well.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ad94d9c and 6f8616f.

📒 Files selected for processing (2)
  • internals/panics.go (1 hunks)
  • struct.go (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
struct.go (1)
internals/panics.go (2)
  • Panicf (12-14)
  • PanicInvalidArgumentsExpectedPointer (9-9)
🪛 GitHub Actions: ci
struct.go

[error] 91-91: Panic triggered inside StructSchema.process during Parse(): Expected destination value to be a pointer but it was not.

internals/panics.go

[error] 13-13: Panic helper invoked: Zog Panic due to invalid destination type passed to Validate/Parse.

@Oudwins Oudwins merged commit 9570fec into master Dec 14, 2025
9 checks passed
@Oudwins Oudwins deleted the feat/better-invalid-arg-panic-message branch December 14, 2025 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant