Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upAdded in error checking for the compile() and expand() functions. #222
Conversation
This comment has been minimized.
This comment has been minimized.
|
Hmm, I don't know how to properly handle error checking within a parallel loop... (didn't have the parallel feature turned on for myself). I can think of one way, to have a shared vector that can hold the results (behind a mutex), then check for any errors in that, otherwise return an Ok. |
alexcrichton
reviewed
Jul 30, 2017
|
Thanks so much for the PR, things are looking great!
Yeah let's leave the signature the same and add a new function.
No worries! I find myself having to do that frequently as well.
Yeah let's just collect the results into a vector and then inspect them after parallel finishes? |
| @@ -266,29 +290,47 @@ impl Config { | |||
| self | |||
| } | |||
|
|
|||
| fn is_flag_supported(&mut self, flag: &str) -> io::Result<bool> { | |||
| fn is_flag_supported(&mut self, flag: &str) -> Result<bool, Error> { | |||
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 30, 2017
Owner
I think the original source of the error here is io::Error, so perhaps this could continue to return a io::Result?
This comment has been minimized.
This comment has been minimized.
marco9999
Jul 31, 2017
Author
Contributor
This function calls get_target() and try_get_compiler(), in which at least get_target() tries to determine if an environment variable exists. The std::env::var() function it calls doesn't return any kind of io::Error (it used to panic if there the result was None), so I don't think its possible to use this?
This comment has been minimized.
This comment has been minimized.
| #[derive(Clone, Debug)] | ||
| pub struct Error { | ||
| /// Describes the kind of error that occurred. | ||
| pub kind: ErrorKind, |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 30, 2017
Owner
We typically try to keep the fields of a struct private for maximal forwards compatibility, so could the ErrorKind enum and the fields of this struct be left private? We could always publicly expose them later, however!
This comment has been minimized.
This comment has been minimized.
dtolnay
Jul 31, 2017
This comment has been minimized.
This comment has been minimized.
marco9999
Jul 31, 2017
Author
Contributor
Sure. What happens when someone tries to use this outside of the crate though? As in, will there be some sort of visibility issue when using the Result<_, Error> from one of the try functions?
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 31, 2017
Owner
Oh so for now you just won't be able to look inside of Error outside this crate. Eventually we can add accessors for various fields and such in a backwards compatible fashion, but for now external users will just see that an Error type exists.
| let output = match cmd.output() { | ||
| Err(_) => return Err(Error { | ||
| kind: ErrorKind::ToolExecError, | ||
| message: "Flag check failed to obtain output.".to_string(), |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 30, 2017
Owner
I think it'd be possible to cut down on the verbosity here by adding:
impl From<io::Error> for Error {
// ...
}and that way you can just use ?!
This comment has been minimized.
This comment has been minimized.
| kind: ErrorKind::IOError, | ||
| message: "Getting object file details failed.".to_string(), | ||
| }), | ||
| }) |
This comment has been minimized.
This comment has been minimized.
alexcrichton
Jul 30, 2017
Owner
This might be a little neater as a helper function, so you could do something like:
dst.join(obj.file_name().ok_or_else(|| err("failed to get details"))?);(or something like that)
This comment has been minimized.
This comment has been minimized.
marco9999
added some commits
Jul 31, 2017
This comment has been minimized.
This comment has been minimized.
|
Are you still supporting rustc 1.9.0? |
marco9999
added some commits
Aug 2, 2017
This comment has been minimized.
This comment has been minimized.
|
Everything looks great to me, thanks so much @marco9999! Want to update the Travis config to inrease the minimum version to a Rust with the |
marco9999
added some commits
Aug 7, 2017
This comment has been minimized.
This comment has been minimized.
|
Updated the rust version to 1.13.0. I think everything is ready... |
alexcrichton
merged commit 1067a72
into
alexcrichton:master
Aug 10, 2017
This comment has been minimized.
This comment has been minimized.
|
Alright merged and good to go, thanks again @marco9999! |
marco9999 commentedJul 29, 2017
Initial attempt to resolve issue #192.
New functions try_compile() and try_expand() have been introduced that returns a result. I have introduced the
Errorstruct type, which is used within the result in the form ofResult<_, Error>. The error contains the type of error (enum ErrorKind, unused for now) and a detailed message (String) to display to the user.I also had to change the signature of the pubic function get_compiler(), in order to propagate errors (in this specific case, it is because of environment vars missing) - if you don't want to do this, maybe I can put in try_get_compiler and get_compiler?
This was pretty fun to work on, I might have a go at some others. One problem I ran into was you can't propagate a
Result<>from a closure (used withinOption<>::unwrap_or_else()calls), so I moved the relevant code out into a match statement instead. Not sure if there was another way to do this, but I at least understand why it's not allowed.