-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Create new Error type to provide more information #28683
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
Conversation
r? @brson (rust_highfive has picked a reviewer for you, use r? to override) |
For more context, Ubuntu's encrypted home directory uses ecryptfs and considering Ubuntu's popularity this is likely to bite someone. |
Thanks for the precisions @gkoz ! |
Such links should instead be hashed or otherwise transformed to adhere to the target filesystem requirements. Erroring here is second worst solution after just panicking. |
I didn't know what solution to choose so I took a compromise. However, hashing is just as fine for me. |
Why did this come up? While something that seems like it could generate an error, it seems like this will never reasonably come up in practice and as a result the extra code needed to handle this isn't worth it. |
It came up while I was working on the OpenCV bindings. thread '' panicked at 'failed to generate documentation: File name too long (os error 63)', ../src/librustdoc/lib.rs:291 I had to generate very long names to get unambiguous names for C functions that wrap C++ methods. In the end, hiding these function from the documentation felt right, so I am not dependent on a fix for the actual issue. That said panicking is terrible, because it does not even give the actual problematic name. (I was not aware functions had their pages, so I was only paying attention to types names, not freestanding functions names). A clean error message would have helped me in this instance. |
Thanks for the info @kali! I think the error handling in librustdoc could definitely use some improvement, and in this case I think the best solution is to just present the error better. @GuillaumeGomez I don't think printing the error or returning a blank error is the right thing to do here, but rather this should be propagated upwards to get printed out at a later time. In theory a bigger infrastructure is also needed for attaching context to errors as it's propagated up the stack (e.g. what Cargo does), but it may be somewhat involved to add. I'd be fine opening an issue if this is getting a little too large for this PR! |
As a status update, some discussion on IRC lead to the conclusion that the best way to handle this was to continue to propagate the error and have it displayed in a more reasonable fashion. E.g. not via printing and returning an error with an empty message. |
4143ae2
to
f2a8d9c
Compare
@alexcrichton: Now the returned error is more complete, is it what you wanted ? Also, there is still the weird panic, do you want me to try to take a look in the same PR ? |
@@ -143,6 +144,33 @@ impl Impl { | |||
} | |||
} | |||
|
|||
#[derive(Debug)] | |||
pub struct IoError { | |||
filename: String, |
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 stored as a PathBuf
as it's what file names are represented by
@alexcrichton: I updated the code. Now we have a difference between a full librustdoc::Error and a simple wrapped io::Error. |
d76654d
to
89b553b
Compare
filename: Some(filename.to_owned()) })); | ||
match render(dst, self, &item, true) { | ||
Ok(ret) => Ok(ret), | ||
Err(e) => Err(Error { error: e, filename: Some(String::new()) }), |
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 has the same problem as before where a blank filename is used to generate a suboptimal error message. This should just be able to use try!
.
Also, if you don't have the From
implementation above, how many instances of try!
are there that no longer work? It seems like this should be one of the few sources of io::Error
-> Error
conversions
89b553b
to
5dbe7e0
Compare
Looking over this again it feels a little too ad-hoc to me. I think that if we're gonna go the route of having a more full-blown error with more contextual information that we'll not want to stop halfway and just add the extra information at only one location. I think removing the |
So I changed a bit how errors are returned. Now what kind of information do you want in the error ? You told me context information, but it has more than one meaning for me so could you precise your thoughts on this please ? And of course, if I forgot anything, please add it ! :) |
} | ||
|
||
impl Error { | ||
pub fn from(e: io::Error) -> Error { |
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 this is basically the previous iteration but in a slightly more verbose fashion due to this. Basically all errors in rustdoc happen when working on some file, so if we want to attach the filename to the errors it should basically always be available to do so. Can you look into making filename not optional?
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's not possible to do this (take a look at build_index and write_shared functions). I'll add it as much places as possible but not all.
6445230
to
4366059
Compare
@GuillaumeGomez I think this is definitely possible to add everywhere, even the |
In this case yes, we can do it. Thanks for the tip ! |
6de69bc
to
6567b00
Compare
} | ||
} | ||
|
||
#[macro_export] |
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 macro shouldn't need to be reexported
d66e3a1
to
15aa338
Compare
And done ! Bonus : we don't have the second weird error message. :) |
@alexcrichton: Is anything missing ? |
Looks good to me, thanks! Could you squash and update the PR title/description for what this currently does? |
15aa338
to
42c01d7
Compare
This PR solves the following issues (or at least help users to understand the problem): ```Rust #![crate_name = "b"] #![crate_type = "rlib"] pub fn his_function_has_a_very_long_name_and_should_make_cargo_doc_explodes_because_it_will_want_to_make_a_filename_with_it_in_excess_of_the_max_filename_length_for_most_filesystem_this_is_not_yet_long_enough_i_need_moreis_function_has_a_very_long_name_and_should_make_cargo_doc_explodes_because_it_will_want_to_make_a_filename_with_it_in_excess_of_the_max_filename_length_for_most_filesystem_this_is_not_yet_long_enough_i_need_more_() {} ``` ```Rust #![crate_name = "b"] #![crate_type = "rlib"] pub struct his_function_has_a_very_long_name_and_should_make_cargo_doc_explodes_because_it_will_want_to_make_a_filename_with_it_in_excess_of_the_max_filename_length_for_most_filesystem_this_is_not_yet_long_enough_i_need_moreis_function_has_a_very_long_name_and_should_make_cargo_doc_explodes_because_it_will_want_to_make_a_filename_with_it_in_excess_of_the_max_filename_length_for_most_filesystem_this_is_not_yet_long_enough_i_need_more_; ``` For the maximum filename length chosen, @gkoz gave me [this link](http://unix.stackexchange.com/a/32834).
This PR solves the following issues (or at least help users to understand the problem):
For the maximum filename length chosen, @gkoz gave me this link.