Skip to content

[validator] fallback to field name w/o json - #2

Merged
capcom6 merged 1 commit into
masterfrom
validator/fallback-to-field-name
Jan 15, 2026
Merged

[validator] fallback to field name w/o json#2
capcom6 merged 1 commit into
masterfrom
validator/fallback-to-field-name

Conversation

@capcom6

@capcom6 capcom6 commented Jan 15, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting by displaying field names in validation error messages when appropriate, enhancing clarity and debuggability.

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

@coderabbitai

coderabbitai Bot commented Jan 15, 2026

Copy link
Copy Markdown

Walkthrough

The change modifies TagNameFunc in validator.go to return the actual struct field name when a JSON tag is empty, instead of returning an empty string. This adjusts error reporting behavior for fields without explicit JSON tags.

Changes

Cohort / File(s) Summary
JSON tag handling enhancement
validator.go
Adds conditional logic to return struct field name (fld.Name) when JSON tag is empty, providing fallback behavior for error reporting on untagged fields.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a fallback to use the field name when the JSON tag is absent, which is exactly what the code modification implements.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.



📜 Recent review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 731993b and d13216b.

📒 Files selected for processing (1)
  • validator.go
🔇 Additional comments (1)
validator.go (1)

23-25: LGTM! Sensible fallback for better error messages.

This correctly handles the case where a struct field has no JSON tag (or uses json:",omitempty" without an explicit name), ensuring validation errors always reference a meaningful field identifier instead of an empty string.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.


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.

@capcom6
capcom6 merged commit d37ae1a into master Jan 15, 2026
4 checks passed
@capcom6
capcom6 deleted the validator/fallback-to-field-name branch January 15, 2026 10:59
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