Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Cause is supported in error_chain! #109

Merged
merged 1 commit into from Jan 4, 2017

Conversation

sfackler
Copy link
Contributor

@sfackler sfackler commented Jan 4, 2017

No description provided.

@Yamakaky Yamakaky merged commit e31f3fb into rust-lang-deprecated:master Jan 4, 2017
@Yamakaky
Copy link
Contributor

Yamakaky commented Jan 4, 2017

Thanks!

@sfackler sfackler deleted the patch-1 branch January 18, 2017 11:53
@Arnavion
Copy link

Is it really supported? Error::cause() always returns either the next_error set in State via chain_err, or the wrapped foreign error. Neither of those appear to be be overriddable with custom cause()

@sfackler
Copy link
Contributor Author

That's weird. The macro syntax definitely allows a cause(...)....

@Arnavion
Copy link

Yes, because quick_error supports it. But error_chain doesn't do anything with it since it has its own codegen.

@Arnavion
Copy link

Simple repro:

#[macro_use]
extern crate error_chain;

error_chain! {
	errors {
		IO(e: ::std::io::Error) {
			cause(e)
		}
	}
}

fn run() -> Result<()> {
	let x = Error::from(ErrorKind::IO(::std::io::Error::from_raw_os_error(1)));
	assert!(::std::error::Error::cause(&x).is_none());

	let y =
		Err::<(), _>(::std::io::Error::from_raw_os_error(1))
		.chain_err(|| ErrorKind::Msg("Msg".to_string()))
		.unwrap_err();
	assert!(::std::error::Error::cause(&y).is_some());

	Err(x) // Will not print "Caused by:"
	// Err(y) // Will print "Caused by:"
}

quick_main!(run);

@Yamakaky
Copy link
Contributor

Oops, you are right, i should revert this commit.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants