Skip to content

Commit

Permalink
Fix ErrorTemplate for variants with empty fields (#14)
Browse files Browse the repository at this point in the history
Signed-off-by: Luka Zakrajšek <[email protected]>
  • Loading branch information
bancek authored Aug 30, 2023
1 parent d4efb57 commit 95b8d9d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion bindgen/templates/ErrorTemplate.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func (err {{ variant_class_name }}) Error() string {
{%- else %}
func (err {{ variant_class_name }}) Error() string {
return fmt.Sprint("{{ variant.name()|class_name }}",
{% if !variant.fields().is_empty() %}": "{% endif %},
{% if !variant.fields().is_empty() %}": ",{% endif %}
{%- for field in variant.fields() %}
{% if !loop.first %}", ",{% endif %}
"{{ field.name()|field_name }}=",
Expand Down
1 change: 1 addition & 0 deletions fixtures/errors/src/errors.udl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ interface ValidationError {
InvalidUser(i32 user_id);
InvalidMessage(string message);
InvalidUserAndMessage(i32 user_id, string message);
UnknownError();
};

[Error]
Expand Down
2 changes: 2 additions & 0 deletions fixtures/errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ pub enum ValidationError {
InvalidMessage { message: String },
#[error("Invalid user {user_id} and message {message}")]
InvalidUserAndMessage { user_id: i32, message: String },
#[error("Unknown error")]
UnknownError,
}

#[derive(Debug, thiserror::Error)]
Expand Down

0 comments on commit 95b8d9d

Please sign in to comment.