Skip to content

Add support for error code#145

Open
lasantosr wants to merge 2 commits into
jprochazk:mainfrom
lasantosr:error-code
Open

Add support for error code#145
lasantosr wants to merge 2 commits into
jprochazk:mainfrom
lasantosr:error-code

Conversation

@lasantosr
Copy link
Copy Markdown
Contributor

This PR would close #105

@lasantosr lasantosr mentioned this pull request Jan 21, 2025
@lasantosr
Copy link
Copy Markdown
Contributor Author

@jprochazk is there something missing to merge this PR?

@aobatact
Copy link
Copy Markdown
Contributor

aobatact commented May 1, 2025

Since compact_str allow you to put 'static str into CompactString, how about using that instead?

Comment thread garde/src/error.rs
self.message.as_ref()
}

pub fn set_code(&mut self, code: impl Into<Cow<'static, str>>) {
Copy link
Copy Markdown

@ghost ghost Sep 2, 2025

Choose a reason for hiding this comment

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

Is it even necessary to allocate the string on the heap? Why can't we just store &'static str everywhere?

If users need the heap-allocated codes, they should be able to make a wrapper for garde::Error with their own implementation of .set_code(...).

Error code (also known as reason) is usually a part of the API Contract and in Google all reasons are usually constants.

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.

Support custom error codes

2 participants