-
Notifications
You must be signed in to change notification settings - Fork 18
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
Added support for thiserror
#18
Closed
+135
−22
Closed
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
db7d306
made displaydoc works with thiserror
TakaakiFuruse 6767b51
downgraded dependency versions, fixed styles according to clippy sugg…
TakaakiFuruse 167686f
re-wrote tests, applied @yaaahc's code
TakaakiFuruse fcea5e5
format fix
TakaakiFuruse a3aa140
added test cases for #[source] attribute
TakaakiFuruse 3c90a1b
[WIP]
TakaakiFuruse File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
use anyhow::anyhow; | ||
use displaydoc::Display; | ||
use std::error::Error as _; | ||
use std::error::Error as StdError; | ||
use std::io; | ||
use thiserror::Error; | ||
|
||
|
@@ -20,13 +20,13 @@ fn test_transparent_for_enum() { | |
|
||
let var = MyError::Variant(anyhow!("inner").context("outer")); | ||
assert_display(&var, "outer"); | ||
// assert_eq!(var.source().unwrap().to_string(), "inner") | ||
assert_eq!(var.source().unwrap().to_string(), "inner") | ||
} | ||
|
||
#[test] | ||
fn test_transparent_for_struct() { | ||
#[derive(Display, Error, Debug)] | ||
#[display(transparent)] | ||
#[error(transparent)] | ||
struct Error(ErrorKind); | ||
|
||
#[derive(Display, Error, Debug)] | ||
|
@@ -44,7 +44,7 @@ fn test_transparent_for_struct() { | |
let io = io::Error::new(io::ErrorKind::Other, "oh no!"); | ||
let error = Error(ErrorKind::from(io)); | ||
assert_eq!("E1", error.to_string()); | ||
// error.source().unwrap().downcast_ref::<io::Error>().unwrap(); | ||
error.source().unwrap().downcast_ref::<io::Error>().unwrap(); | ||
} | ||
|
||
#[test] | ||
|
@@ -68,3 +68,31 @@ fn test_errordoc_for_struct() { | |
} | ||
assert_display(MyError { variant: 42 }, "I'm a doc for MyError"); | ||
} | ||
|
||
#[test] | ||
fn test_thiserror_implicit_and_source_works() { | ||
#[derive(Display, Error, Debug)] | ||
#[error("implicit source")] | ||
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. these are only passing because you're using Try doing an enum like this as a test case #[derive(Debug, Display, Error)]
enum SourceError {
#[error(transparent)]
#[display(transparent)]
ImplicitSource {
source: io::Error,
},
#[error(transparent)]
#[display(transparent)]
ExplicitSource {
source: String,
#[source]
io: io::Error,
},
/// There isnt really a {source}
DocSourceless {
source: String,
},
} |
||
struct ImplicitSource { | ||
source: io::Error, | ||
} | ||
|
||
#[derive(Display, Error, Debug)] | ||
#[error("explicit source")] | ||
struct ExplicitSource { | ||
source: String, | ||
#[source] | ||
io: io::Error, | ||
} | ||
|
||
let io = io::Error::new(io::ErrorKind::Other, "oh no!"); | ||
let error = ImplicitSource { source: io }; | ||
error.source().unwrap().downcast_ref::<io::Error>().unwrap(); | ||
|
||
let io = io::Error::new(io::ErrorKind::Other, "oh no!"); | ||
let error = ExplicitSource { | ||
source: String::new(), | ||
io, | ||
}; | ||
error.source().unwrap().downcast_ref::<io::Error>().unwrap(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This is the only test failing now.