-
Notifications
You must be signed in to change notification settings - Fork 22
Conversation
@steveklabnik curious is there a reason to move towards that over error-chain? |
src/lib.rs
Outdated
@@ -172,9 +181,9 @@ pub fn build(config: &Config, artifacts: &[&str]) -> Result<()> { | |||
.stderr(Stdio::piped()) | |||
.spawn() | |||
.map_err(|e| if e.kind() == io::ErrorKind::NotFound { | |||
Error::with_chain(e, format!("frontend `{}` not found", frontend)) | |||
format_err!("frontend `{}` not found", frontend).into() |
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.
It looks like you could use chain()
to keep the context here?
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.
wait, what's chain()? I don't see it in failure's docs
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.
Looks like it's been renamed to context
? It looks like it works slightly differently than chain_err
did in error_chain
? Hard to say without trying it 😂
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.
Yea I renamed it to context. You could do e.context(format!(...)).into()
here.
src/lib.rs
Outdated
@@ -196,8 +205,8 @@ pub fn build(config: &Config, artifacts: &[&str]) -> Result<()> { | |||
|
|||
/// Run all documentation tests. | |||
pub fn test(config: &Config) -> Result<()> { | |||
let doc_json = File::open(config.documentation_path()).chain_err( | |||
|| "could not find generated documentation", | |||
let doc_json = File::open(config.documentation_path()).map_err(|_| |
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.
Same here.
This looks interesting! |
It's speculated that this kind of library may be preferable to error-chain overall; I wanted to give it a shot to see what the diff looks like. I think I personally prefer it, but the only way to find out is to give it a try. |
Awesome! |
@withoutboats while working on the test part of this PR,
Do you have to do something specific to use |
|
Thanks boats! Now our test is failing because of the way we test the context; I suspect that I have to update the macro in some way. More work needed. |
In this case, it might just be better to check that the cause is the expected type and always return an |
ea4870c
to
5bace42
Compare
I've rebased this, and it compiles, but has test failures about not being able to find the source test crates. Hrm. |
Ohh interesting! https://travis-ci.org/steveklabnik/rustdoc/jobs/305812561 even though #203 passed, it's now failing. So it's likely that PR, not this one.... @euclio any ideas? |
Failing on master too. Probably related to a change in how the analysis is generated. I did a quick test and it should be fixable by updating |
ah, that makes perfect sense. ill dig in. |
5bace42
to
9dadf6c
Compare
Updated and rebased, still failing. I must have missed something somewhere... |
oh wait looks like a bad rebase.... |
9dadf6c
to
0e72672
Compare
Got master passing, this seems to reintroduce it. Hmmmmmmmmm |
0e72672
to
6936fef
Compare
failure is becoming the de-facto error handling crate.
6936fef
to
06ed65c
Compare
@mgattozzi @euclio okay I think this is ready for a review, maybe you'll spot where I messed up. @withoutboats if you have a second as well, that'd be nice. |
tests/source.rs
Outdated
|
||
Directive::Has(regex) | ||
} | ||
"matches" => { | ||
ensure!(args.len() == 2, "not enough arguments"); | ||
if args.len() == 2 { |
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 should be if args.len() != 2
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.
lol oops
tests/source.rs
Outdated
|
||
Directive::Matches(value) | ||
} | ||
"assert" => { | ||
ensure!(args.len() == 1, "expected 1 argument"); | ||
if args.len() == 1 { |
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 should be if args.len() != 1
Awesome, thank you! Of course I messed that up... that leads to just one failure now. |
tests/source.rs
Outdated
@@ -391,7 +413,7 @@ fn parse_test(line: &str) -> Option<Result<TestCase>> { | |||
if let Some(caps) = DIRECTIVE_RE.captures(line) { | |||
let directive = &caps["directive"]; | |||
let result = parse_directive(directive, &caps["args"], caps.name("negated").is_some()) | |||
.chain_err(|| ErrorKind::InvalidDirective(line.into())); | |||
.map_err(|e| e.context(InvalidDirective { d: line.into() }).into()); |
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.
I think the context is backwards here. I think that parse_test
should return Option<Result<TestCase, InvalidDirective>>
. Make sure to set the context of the InvalidDirective
error to be the original error. The tests should then check that err.cause()
is the expected type.
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.
yeah, this is sorta what i'm thinking as well. been toying with this...
@@ -401,37 +423,49 @@ fn parse_test(line: &str) -> Option<Result<TestCase>> { | |||
fn parse_directive(directive: &str, args: &str, negated: bool) -> Result<TestCase> { | |||
let args = match shlex::split(args) { |
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 can be ok_or_else
Looks good with comments addressed. Any reason you're preferring |
no reason; I'll run clippy too. now dealing with this fun error:
hmmmmmmmmmmmmmmmmm |
Yeah, I was confused by that too. Does downcasting the cause to |
It doesn't seem to, no matter what I try to cast it to, it doesn't seem to do the right thing. Hrm. |
@euclio so check out this last commit: if we do make it always return |
Exactly. Error/ErrorKind could work, but since this is an internal-only error that complexity might not be warranted. We could just make it an enum like here. |
Time to |
This PR ports us from error-chain to @withoutboats'
failure
crate.I'm done for the day so there's probably CI failures and such, but I wanted to toss this up there so that everyone can see.
/cc @aturon @alexcrichton