-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace Option::unwrap() with Option::ok_or_else() with descriptive message #56
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,14 @@ pub trait SerdeAPI: Serialize + for<'a> Deserialize<'a> { | |
/// # Returns: | ||
/// | ||
/// A Rust Result | ||
fn to_file(&self, filename: &str) -> Result<(), anyhow::Error> { | ||
fn to_file(&self, filename: &str) -> anyhow::Result<()> { | ||
let file = PathBuf::from(filename); | ||
match file.extension().unwrap().to_str().unwrap() { | ||
match file | ||
.extension() | ||
.ok_or_else(|| anyhow!("Unable to parse file extension: {:?}", file))? | ||
.to_str() | ||
.unwrap() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @kylecarow , I'd lean toward also getting rid of this unwrap with a separate message since it's not much additional effort. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @calbaker done, see latest commit |
||
{ | ||
"json" => serde_json::to_writer(&File::create(file)?, self)?, | ||
"yaml" => serde_yaml::to_writer(&File::create(file)?, self)?, | ||
_ => serde_json::to_writer(&File::create(file)?, self)?, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kylecarow , I think you could change
to something like
to preserve whatever the native error message is as context.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm, I don't know that the native error message really exists. The
unwrap
was on anOption
, not aResult
, so the error was just about unwrapping on aNone