Skip to content

Commit

Permalink
Fix stack overflow caused by displaying errors (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
KyleMayes committed Oct 2, 2020
1 parent bcb0df7 commit ba947f4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.0.2] - 2020-08-16

### Fixed
- Fixed stack overflow caused by displaying errors

## [1.0.1] - 2020-08-16

### Fixed
Expand Down
14 changes: 5 additions & 9 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ macro_rules! error {
$(#[$variantdoc] $variant), +
}

impl Error for $name {
fn description(&self) -> &str {
match *self {
$($name::$variant => $message), +
}
}
}
impl Error for $name { }

impl From<$name> for String {
fn from(error: $name) -> String {
Expand All @@ -62,8 +56,10 @@ macro_rules! error {
}

impl fmt::Display for $name {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
write!(formatter, "{}", self)
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
$($name::$variant => write!(f, $message)), +
}
}
}
};
Expand Down
4 changes: 4 additions & 0 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ fn test() {

sonar_test::test(&clang);

// SourceError _______________________________

assert_eq!(format!("{}", SourceError::Unknown), "an unknown error occurred");

// Entity ____________________________________

let source = "
Expand Down

0 comments on commit ba947f4

Please sign in to comment.