Skip to content

Commit

Permalink
Merge pull request #6 from StripedCats/features/complete-error-display
Browse files Browse the repository at this point in the history
Fill unimplemented error enum fields (trait Display)
  • Loading branch information
Genarito authored Jul 5, 2022
2 parents 7cfa654 + c3822f9 commit 1490e4d
Showing 1 changed file with 39 additions and 5 deletions.
44 changes: 39 additions & 5 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,50 @@ impl de::Error for Error {

impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use Error::*;

match self {
Error::Syntax(msg) => write!(
Syntax(msg) => write!(
f,
"Input text does not have a valid Gura format. Parsing failed with error \"{}\"",
msg
),
Error::Message(msg) => write!(f, "{}", msg),
Error::Eof => f.write_str("Unexpected end of input"),
Error::UnitNotSupported => f.write_str("Unit values are not supported in Gura"),
_ => unimplemented!(),
Message(msg) => write!(f, "{}", msg),
Eof => f.write_str("Unexpected end of input"),
UnitNotSupported => f.write_str("Unit values are not supported in Gura"),

ExpectedBytes => f.write_str("Expected byte sequence"),
ExpectedBoolean => f.write_str("Expected boolean"),
ExpectedInteger => f.write_str("Expected integer"),
ExpectedFloat => f.write_str(
concat!(
"Expected float: perhaps you forgot decimal fractional part",
" (No implicit coversion between int and float, ",
"see https://gura.netlify.app/docs/spec#float)"
)
),
ExpectedChar => f.write_str("Expected char"),
ExpectedString => f.write_str("Expected string"),
ExpectedNull => f.write_str("Expected null value"),
ExpectedArray => f.write_str("Expected array"),
ExpectedArrayEnd => f.write_str("Expected array end"),

ExpectedMap => f.write_str("Expected map"),
ExpectedMapColon => f.write_str("Expected colon at map"),
ExpectedMapComma => f.write_str("Expected comma at map"),
ExpectedMapEnd => f.write_str("Expected map end"),

ExpectedEnum => f.write_str("Expected enum value"),

ExpectedObjectValue => f.write_str("Expected not empty object block"),
TrailingCharacters => f.write_str("Invalid trailing characters"),

ExpectedUnitVariant => f.write_str("Expected unit variant at enum"),

ExpectedArrayComma => f.write_str("Expected comma at array"),

InvalidType => f.write_str("Invalid type"),
ExpectedIdentifier => f.write_str("Expected identifier")
}
}
}
Expand Down

0 comments on commit 1490e4d

Please sign in to comment.