From 95b8d9dc52406b79adf39eb435fc6c2a3d553fc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Zakraj=C5=A1ek?= Date: Wed, 30 Aug 2023 09:26:12 +0200 Subject: [PATCH] Fix ErrorTemplate for variants with empty fields (#14) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luka Zakrajšek --- bindgen/templates/ErrorTemplate.go | 2 +- fixtures/errors/src/errors.udl | 1 + fixtures/errors/src/lib.rs | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/bindgen/templates/ErrorTemplate.go b/bindgen/templates/ErrorTemplate.go index decae07..837f1f0 100644 --- a/bindgen/templates/ErrorTemplate.go +++ b/bindgen/templates/ErrorTemplate.go @@ -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 }}=", diff --git a/fixtures/errors/src/errors.udl b/fixtures/errors/src/errors.udl index 360f3e5..c8fc765 100644 --- a/fixtures/errors/src/errors.udl +++ b/fixtures/errors/src/errors.udl @@ -24,6 +24,7 @@ interface ValidationError { InvalidUser(i32 user_id); InvalidMessage(string message); InvalidUserAndMessage(i32 user_id, string message); + UnknownError(); }; [Error] diff --git a/fixtures/errors/src/lib.rs b/fixtures/errors/src/lib.rs index 218b330..7b07383 100644 --- a/fixtures/errors/src/lib.rs +++ b/fixtures/errors/src/lib.rs @@ -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)]