Skip to content

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

Merged
merged 1 commit into from
Oct 17, 2015

Conversation

GuillaumeGomez
Copy link
Member

This PR solves the following issues (or at least help users to understand the problem):

#![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_() {}
#![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.

@rust-highfive
Copy link
Contributor

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@gkoz
Copy link
Contributor

gkoz commented Sep 26, 2015

For the maximum filename length chosen, @gkoz gave me this link.

For more context, Ubuntu's encrypted home directory uses ecryptfs and considering Ubuntu's popularity this is likely to bite someone.

@GuillaumeGomez
Copy link
Member Author

Thanks for the precisions @gkoz !

@nagisa
Copy link
Member

nagisa commented Sep 27, 2015

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.

@GuillaumeGomez
Copy link
Member Author

I didn't know what solution to choose so I took a compromise. However, hashing is just as fine for me.

@alexcrichton
Copy link
Member

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.

@kali
Copy link
Contributor

kali commented Sep 29, 2015

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.

@alexcrichton
Copy link
Member

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!

@brson brson assigned alexcrichton and unassigned brson Sep 30, 2015
@alexcrichton
Copy link
Member

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.

@GuillaumeGomez
Copy link
Member Author

@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,
Copy link
Member

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

@GuillaumeGomez
Copy link
Member Author

@alexcrichton: I updated the code. Now we have a difference between a full librustdoc::Error and a simple wrapped io::Error.

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()) }),
Copy link
Member

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

@alexcrichton
Copy link
Member

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 From implementation will be a good indicator of what call sites need to be fixed up, and ideally there's no From implementation at all (as it requires losing contextual information).

@GuillaumeGomez
Copy link
Member Author

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 {
Copy link
Member

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?

Copy link
Member Author

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.

@alexcrichton
Copy link
Member

@GuillaumeGomez I think this is definitely possible to add everywhere, even the build_index and write_shared functions. All errors will originate because of some filename in rustdoc. The usage in build_index should be .unwrap() because a Write into a Cursor<Vec<u8>> will never fail.

@GuillaumeGomez
Copy link
Member Author

In this case yes, we can do it. Thanks for the tip !

@GuillaumeGomez GuillaumeGomez force-pushed the rustdoc_error branch 3 times, most recently from 6de69bc to 6567b00 Compare October 12, 2015 22:01
}
}

#[macro_export]
Copy link
Member

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

@GuillaumeGomez GuillaumeGomez force-pushed the rustdoc_error branch 2 times, most recently from d66e3a1 to 15aa338 Compare October 14, 2015 20:13
@GuillaumeGomez
Copy link
Member Author

And done ! Bonus : we don't have the second weird error message. :)

@GuillaumeGomez
Copy link
Member Author

@alexcrichton: Is anything missing ?

@alexcrichton
Copy link
Member

Looks good to me, thanks! Could you squash and update the PR title/description for what this currently does?

@GuillaumeGomez GuillaumeGomez changed the title Add checkup on filename length and print out an error message Create new Error type to provide more information Oct 16, 2015
@alexcrichton
Copy link
Member

@bors: r+ 42c01d7

bors added a commit that referenced this pull request Oct 16, 2015
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).
@bors
Copy link
Collaborator

bors commented Oct 16, 2015

⌛ Testing commit 42c01d7 with merge 20a6938...

@bors bors merged commit 42c01d7 into rust-lang:master Oct 17, 2015
@GuillaumeGomez GuillaumeGomez deleted the rustdoc_error branch October 17, 2015 09:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants