Skip to content

Add information about violations to error message - #554

Merged
anuraaga merged 3 commits into
bufbuild:mainfrom
anuraaga:error-message
Oct 23, 2026
Merged

anuraaga merged 3 commits into
bufbuild:mainfrom
anuraaga:error-message

Conversation

@anuraaga

@anuraaga anuraaga commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

This follows the same style as protovalidate-es, one violation in the message and a count if there are more than one.

Fixes #546

/cc @stefanvanburen

@anuraaga
anuraaga requested a review from jonbodner-buf October 9, 2026 01:53
@stefanvanburen

Copy link
Copy Markdown
Contributor

Seems reasonable to me once y'all agree in bufbuild/protovalidate#536 :)

violation.message.as_deref().unwrap_or_default(),
violation.rule_id.as_deref().unwrap_or_default(),
) {
("", "") => f.write_str("[unknown]"),

@jonbodner-buf jonbodner-buf Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if both are present, why not display both?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This was to apply the change made to Go in bufbuild/protovalidate-go#291 (comment) here. I don't feel too strongly either way but it was suggested in bufbuild/protovalidate#536, lean towards going with it

impl fmt::Display for ValidationError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str("validation failed")
write_violation(f, &self.violations[0])?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe support a # flag to display all violation messages.

@anuraaga anuraaga Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is a great idea for rust! Python doesn't have anything like that (just the thrown exception), so let's keep this as-is for now and possibly add it in the future if supporting rust itself to prevent dead code here

@jonbodner-buf jonbodner-buf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Some additional ideas we should consider standardizing

@anuraaga

Copy link
Copy Markdown
Contributor Author

@jonbodner-buf thanks! I think on bufbuild/protovalidate#536 we are quite close to settling on doing minimal changes there. So if what we have here seems ok, would like to go with it

@jonbodner-buf
jonbodner-buf self-requested a review October 22, 2026 15:41
@jonbodner-buf

Copy link
Copy Markdown
Contributor

Approved it.

@anuraaga
anuraaga merged commit 2222e17 into bufbuild:main Oct 23, 2026
46 checks passed
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.

[Feature Request] Include violations in ValidationError's message

3 participants