Skip to content

Commit 6690d7e

Browse files
committed
use type name in Display impl for errors with no other message set
Otherwise, with nested errors, you can end up with unhelpful errors like this (example printed by `anyhow`): ``` Error: failed to get metadata for "/temp/spoopadoop" Caused by: 0: Dropbox API endpoint returned an error: There is nothing at the given path. 1: There is nothing at the given path. 2: There is nothing at the given path. ``` instead, with this change, you get: ``` Error: failed to get metadata for "/temp/spoopadoop" Caused by: 0: Dropbox API endpoint returned an error: GetMetadataError: There is nothing at the given path. 1: GetMetadataError: There is nothing at the given path. 2: There is nothing at the given path. ``` which is less repetitive and gives a better indication of what actually went wrong.
1 parent 0ed284c commit 6690d7e

File tree

7 files changed

+95
-92
lines changed

7 files changed

+95
-92
lines changed

generator/rust.stoneg.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,9 @@ def _impl_display(self, typ: ir.DataType) -> None:
11441144
msg = msg[:-1]
11451145
if msg:
11461146
msg += ': '
1147+
else:
1148+
# if there's no message for the variant, use the type name
1149+
msg = f"{type_name}: "
11471150
msg += inner_fmt
11481151
args = 'inner'
11491152

src/generated/types/file_properties.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ impl ::std::fmt::Display for AddPropertiesError {
301301
match self {
302302
AddPropertiesError::TemplateNotFound(inner) => write!(f, "Template does not exist for the given identifier: {:?}", inner),
303303
AddPropertiesError::RestrictedContent => f.write_str("You do not have permission to modify this template."),
304-
AddPropertiesError::Path(inner) => write!(f, "{}", inner),
304+
AddPropertiesError::Path(inner) => write!(f, "AddPropertiesError: {}", inner),
305305
AddPropertiesError::UnsupportedFolder => f.write_str("This folder cannot be tagged. Tagging folders is not supported for team-owned templates."),
306306
AddPropertiesError::PropertyFieldTooLarge => f.write_str("One or more of the supplied property field values is too large."),
307307
AddPropertiesError::DoesNotFitTemplate => f.write_str("One or more of the supplied property fields does not conform to the template specifications."),
@@ -911,7 +911,7 @@ impl ::std::fmt::Display for InvalidPropertyGroupError {
911911
match self {
912912
InvalidPropertyGroupError::TemplateNotFound(inner) => write!(f, "Template does not exist for the given identifier: {:?}", inner),
913913
InvalidPropertyGroupError::RestrictedContent => f.write_str("You do not have permission to modify this template."),
914-
InvalidPropertyGroupError::Path(inner) => write!(f, "{}", inner),
914+
InvalidPropertyGroupError::Path(inner) => write!(f, "InvalidPropertyGroupError: {}", inner),
915915
InvalidPropertyGroupError::UnsupportedFolder => f.write_str("This folder cannot be tagged. Tagging folders is not supported for team-owned templates."),
916916
InvalidPropertyGroupError::PropertyFieldTooLarge => f.write_str("One or more of the supplied property field values is too large."),
917917
InvalidPropertyGroupError::DoesNotFitTemplate => f.write_str("One or more of the supplied property fields does not conform to the template specifications."),
@@ -1624,7 +1624,7 @@ impl ::std::fmt::Display for PropertiesError {
16241624
match self {
16251625
PropertiesError::TemplateNotFound(inner) => write!(f, "Template does not exist for the given identifier: {:?}", inner),
16261626
PropertiesError::RestrictedContent => f.write_str("You do not have permission to modify this template."),
1627-
PropertiesError::Path(inner) => write!(f, "{}", inner),
1627+
PropertiesError::Path(inner) => write!(f, "PropertiesError: {}", inner),
16281628
PropertiesError::UnsupportedFolder => f.write_str("This folder cannot be tagged. Tagging folders is not supported for team-owned templates."),
16291629
_ => write!(f, "{:?}", *self),
16301630
}
@@ -1983,7 +1983,7 @@ impl ::std::error::Error for PropertiesSearchError {
19831983
impl ::std::fmt::Display for PropertiesSearchError {
19841984
fn fmt(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
19851985
match self {
1986-
PropertiesSearchError::PropertyGroupLookup(inner) => write!(f, "{}", inner),
1986+
PropertiesSearchError::PropertyGroupLookup(inner) => write!(f, "PropertiesSearchError: {}", inner),
19871987
_ => write!(f, "{:?}", *self),
19881988
}
19891989
}
@@ -3300,9 +3300,9 @@ impl ::std::fmt::Display for RemovePropertiesError {
33003300
match self {
33013301
RemovePropertiesError::TemplateNotFound(inner) => write!(f, "Template does not exist for the given identifier: {:?}", inner),
33023302
RemovePropertiesError::RestrictedContent => f.write_str("You do not have permission to modify this template."),
3303-
RemovePropertiesError::Path(inner) => write!(f, "{}", inner),
3303+
RemovePropertiesError::Path(inner) => write!(f, "RemovePropertiesError: {}", inner),
33043304
RemovePropertiesError::UnsupportedFolder => f.write_str("This folder cannot be tagged. Tagging folders is not supported for team-owned templates."),
3305-
RemovePropertiesError::PropertyGroupLookup(inner) => write!(f, "{}", inner),
3305+
RemovePropertiesError::PropertyGroupLookup(inner) => write!(f, "RemovePropertiesError: {}", inner),
33063306
_ => write!(f, "{:?}", *self),
33073307
}
33083308
}
@@ -3971,12 +3971,12 @@ impl ::std::fmt::Display for UpdatePropertiesError {
39713971
match self {
39723972
UpdatePropertiesError::TemplateNotFound(inner) => write!(f, "Template does not exist for the given identifier: {:?}", inner),
39733973
UpdatePropertiesError::RestrictedContent => f.write_str("You do not have permission to modify this template."),
3974-
UpdatePropertiesError::Path(inner) => write!(f, "{}", inner),
3974+
UpdatePropertiesError::Path(inner) => write!(f, "UpdatePropertiesError: {}", inner),
39753975
UpdatePropertiesError::UnsupportedFolder => f.write_str("This folder cannot be tagged. Tagging folders is not supported for team-owned templates."),
39763976
UpdatePropertiesError::PropertyFieldTooLarge => f.write_str("One or more of the supplied property field values is too large."),
39773977
UpdatePropertiesError::DoesNotFitTemplate => f.write_str("One or more of the supplied property fields does not conform to the template specifications."),
39783978
UpdatePropertiesError::DuplicatePropertyGroups => f.write_str("There are 2 or more property groups referring to the same templates in the input."),
3979-
UpdatePropertiesError::PropertyGroupLookup(inner) => write!(f, "{}", inner),
3979+
UpdatePropertiesError::PropertyGroupLookup(inner) => write!(f, "UpdatePropertiesError: {}", inner),
39803980
_ => write!(f, "{:?}", *self),
39813981
}
39823982
}

0 commit comments

Comments
 (0)