Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor ListError to Use quick-error
- Loading branch information
Showing
5 changed files
with
49 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,24 @@ | ||
use std::fmt; | ||
use std::error::Error; | ||
|
||
#[derive(Debug)] | ||
pub enum ListError { | ||
SectionMissing(String), | ||
VersionMissing(String), | ||
} | ||
|
||
impl Error for ListError { | ||
fn description(&self) -> &'static str { | ||
match *self { | ||
ListError::SectionMissing(_) => "Couldn't read section", | ||
ListError::VersionMissing(_) => "Couldn't read version", | ||
quick_error! { | ||
#[derive(Debug)] | ||
pub enum ListError { | ||
SectionMissing(section: String) { | ||
description("Couldn't read section") | ||
display("Couldn't read section `{}`.", section) | ||
} | ||
VersionMissing(dep: String, section: String) { | ||
description("Couldn't read version") | ||
display("Couldn't read version of `{}` in section `{}`.", dep, section) | ||
} | ||
PackagesMissing { | ||
description("Couldn't read list of packages in `Cargo.lock` file.") | ||
} | ||
PackageInvalid { | ||
description("Invalid package record") | ||
display("Invalid package record in `Cargo.lock`") | ||
} | ||
PackageFieldMissing(field: &'static str) { | ||
description("Field missing in package record") | ||
display("Field `{}` missing in package record in `Cargo.lock`.", field) | ||
} | ||
} | ||
} | ||
|
||
impl fmt::Display for ListError { | ||
fn fmt(&self, format: &mut fmt::Formatter) -> Result<(), fmt::Error> { | ||
let desc: String = match *self { | ||
ListError::SectionMissing(ref name) => format!("Couldn't read section {}", name), | ||
ListError::VersionMissing(ref name) => format!("Couldn't read version of {}", name), | ||
}; | ||
format.write_str(&desc) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,7 +205,7 @@ impl Manifest { | |
if empty { | ||
section.remove(); | ||
} | ||
}; | ||
} | ||
result | ||
} | ||
} | ||
|