Skip to content
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

Better errors #16619

Closed
wants to merge 3 commits into from
Closed

Conversation

steveklabnik
Copy link
Member

This is the start of my attempt to address #2092.

What this is

Right now, when you compile with an error, you get this:

steve@computer:~/tmp$ cat hello.rs 
fn foo(x: int) {
    match x {
        1 .. 10 => (),
        7       => (),
        _       => (),
    }
}

fn main() {

}
steve@computer:~/tmp$ rustc hello.rs 
hello.rs:4:9: 4:10 error: unreachable pattern [E0001] (pass `--explain E0001` to see a detailed explanation)
hello.rs:4         7       => (),
                   ^
error: aborting due to previous error

Note the [E0001] error code and the ability to get an explanation.

steve@computer:~/tmp$ rustc --explain E0001

    This error suggests that the expression arm corresponding to the noted pattern
    will never be reached as for all possible values of the expression being matched,
    one of the preceeding patterns will match.

    This means that perhaps some of the preceeding patterns are too general, this
    one is too specific or the ordering is incorrect.

This is sweet! But we can do better.

What this adds

With this PR applied, you get this instead:

steve@computer:~/tmp$ rustc hello.rs 
hello.rs:4:9: 4:10 error: unreachable pattern [E0001] (pass `--explain E0001` to see more detail or visit http://doc.rust-lang.org/errors/E0001.html for extensive help with this error)
hello.rs:4         7       => (),
                   ^
error: aborting due to previous error

Along with the doc machinery to generate that page. This should give us a place to provide even more help around errors, and guide people through problems. If they don't have an internet connection, they can see the pages locally as well.

This PR isn't really 'ready' yet, but I wanted to get some feedback. The error pages don't display CSS correctly, and I think I screwed up my git-fu to fix that error message, but I'm about to jump on a plane. Please let me know what you think, and I'll keep working on this if it's a path we want to go down.

I tried to keep this in a similar style to what exists, but we
don't need to whitelist errors. This will be a long, repetitive list,
we should just build everything that's there.
@vks
Copy link
Contributor

vks commented Aug 20, 2014

I think at the moment it is too verbose for a default error message, maybe only show it when passing --explain?

I really like the idea! On the error website we could also link to other resources that might help (IRC etc.).

@jroesch
Copy link
Member

jroesch commented Aug 20, 2014

cc me

@Gankra
Copy link
Contributor

Gankra commented Aug 20, 2014

This is wonderful, and I'd love to help make this more wonderful! Some thoughts:

  • Maybe show only (pass --explain E0001 to see more detail), and have --explain provide the extended discussion URL message? This reduces clutter in the compiler output, and provides a nice simple > moderate > advanced progression of the documentation.
  • Is the contents of --explain extracted or related to the .md at all? This would seem desirable to avoid maintaining multiple similar documents, and avoid drift/rot.
  • Do we want all error help pages to be loose static pages, or do we want the markdown to be parsed and embedded inside a general template like libs?
  • Do we want the errors to be indexed and serachable in the same way as libs?

@huonw
Copy link
Member

huonw commented Aug 20, 2014

I agree that this makes the error messages too verbose; it's not rare for people on IRC to essentially just ignore what the error message is telling them, because it's just too long (e.g. the "did you mean" suggestions for lifetimes have a long error message, but they include the correct information, but people still just ignore it).

I idly wonder if it's worth supporting nested directories for formatting the doc pages, because we could easily accumulate thousands of them, e.g. E00/E0001.md ... E01/E0123.md ... E02/E0234.md (they would all be rendered to error/Ennnn.html though). shrug

(This should definitely be possible in future, and possibly overengineering.)

Do we want all error help pages to be loose static pages, or do we want the markdown to be parsed and embedded inside a general template like libs?

If they were more connected to the diagnostics macros themselves, we could e.g. have --explain show the same content (especially if we get some form of plain text output for rustdoc, but this would be a somewhat circular dependency...), and possibly make sure that the numbers connect to pages 'correctly'.

@huonw
Copy link
Member

huonw commented Aug 20, 2014

The error pages don't display CSS correctly

I think this is because this line is including <link src="rust.css" ...> (or whatever the syntax is) in the HTML; this is fine for the other docs, since rust.css is in the same directory, but should be ../rust.css for these pages, since they're in the error subdir.

@richo
Copy link
Contributor

richo commented Aug 20, 2014

I almost feel like this should be hidden behind a switch (or at least opt-out-able).

I use a lot of tools that deal with the output of the compiler (and believe I'm not alone in doing this), and the long lines with links in them would significantly clutter up the flow.

Bullish on the principle, but not stoked about the implementation.

@killercup
Copy link
Member

Where does the error description in --explain come from? It would probably be a good idea to only have this text in one place.

@ftxqxd
Copy link
Contributor

ftxqxd commented Aug 20, 2014

This is exciting! 😃 I love how extensive Rust’s documentation is getting now. I do share the concerns about long error messages, though.

Maybe this could be separated into a note-like message, similar to the note: expansion site message that appears when an error occurs in a macro expansion? To make it stand out more, perhaps it could be changed to a different colour as well. (Notes are green, warnings are yellow, and errors are red, so maybe this could be a cyan ‘help’ message or something?) Combining this with @vks’s and @gankro’s suggestion of moving the URL to the --explain description, the error looks like this:

hello.rs:4:9: 4:10 error: unreachable pattern [E0001]
hello.rs:4         7       => (),
                   ^
help: pass `--explain E0001` to see more detail
error: aborting due to previous error

which is quite a lot shorter (horizontally) than what we have now, even without this change. The help message would also stand out if it were a different colour, hopefully drawing people’s attention to it.

Regarding duplication of explanations, I think this could be handled later. I’d like it if the --explain description were automatically spliced into the online ‘Summary’ section, but that makes rendering these docs quite complex…

@stormpat
Copy link

Great idea! Reminds me of angulars error messages, with links to error pages with more details.

@steveklabnik
Copy link
Member Author

Theres a few things here:

Maybe show only (pass --explain E0001 to see more detail), and have --explain provide the extended discussion URL message? This reduces clutter in the compiler output, and provides a nice simple > moderate > advanced progression of the documentation.

There's tension here: better error output is better for newbies, and more terse output is better for more experienced people or, as @richo mentioned, parsing output. I'm not sure where the right mixture is here.

@huonw you're right about the CSS.

One thing with not matching up the explain text: it allows for a 'short' and 'long' form explanation. Maybe the right answer is to put the URL at the bottom of each explain text, leave the explain in the register call for now, like it is, and leave the extended explanation as the page.

I idly wonder if it's worth supporting nested directories for formatting the doc pages,

Is this because of a lack of inodes or something?

Do we want all error help pages to be loose static pages, or do we want the markdown to be parsed and embedded inside a general template like libs?

It's already embedded inside of the general template, though I'd imagine that eventually, we'd want to change the template around a tiny bit. Unsure.

I really like @P1start 's help: idea, though I have no idea how to implement it.

@Gankra
Copy link
Contributor

Gankra commented Aug 20, 2014

@steveklabnik I was thinking something along the lines of --explain outputting the first "section" of what would show up on the full web page. In particular, code samples and references won't show up well in terminal output (I think?), and I think those should be reserved for web.

@steveklabnik
Copy link
Member Author

I was thinking something along the lines of --explain outputting the first "section" of what would show up on the full web page.

This can work, but it also means that it can be awkward sometimes. I'm torn.

(but you're totally right about code, etc)

@Gankra
Copy link
Contributor

Gankra commented Aug 20, 2014

@steveklabnik I'm thinking of the following hierarchy/flow:

  • Bug occurs: Print the minimal name/desc of the bug, with error number, in terminal, provide usual "hints", and then P1's help message at the bottom. Anyone who clearly sees what the issue really is, isn't distracted. Rookies see the "help" message as the last thing (and are therefore more likely to register it?).
  • Explain is passed: Print "this is a summary of the issue, for an indepth explanation, see [URL]", and then print the first section of the web page (everything before the first header, maybe?), which should be an introduction/summary anyway. People who have seen the issue before, or almost understand what's going are easily refreshed/clarified on what this issue is.
  • Web page is visited: Everything You Need To Know On This Issue. For those who really don't get why this is an issue, or what the issue even is.

@steveklabnik
Copy link
Member Author

Rookies see the "help" message as the last thing (and are therefore more likely to register it?).

I'm not sure this is true, but I don't think there's any way to figure it out, really. It'd also be nice if it were 😄

@steveklabnik
Copy link
Member Author

(I do like this proposal, though)

@mdinger
Copy link
Contributor

mdinger commented Aug 20, 2014

Technically, being brief isn't a huge problem because people often paste weird error messages into Google. Don't know that error C1245 is from visual studio? Search VS error C1245 and you'll usually find a good help page if it's a compiler error.

Verbosity may also be a GUI issue. Visual studio (the older version I used...maybe not the new one) pastes compiler output verbatim. Qt Creator has a second mode which collects the brief descriptions together and only shows the expanded output when you click on the item to expand it. GUIs are probably outside the scope of this bug though.

@steveklabnik
Copy link
Member Author

Don't know that error C1245 is from visual studio? Search VS error C1245 and you'll usually find a good help page if it's a compiler error.

Right, this is the big win of giving them pages in the docs, IMHO.

@vks
Copy link
Contributor

vks commented Aug 20, 2014

I'm not sure this is true, but I don't think there's any way to figure it out, really. It'd also be nice if it were 😄

I think this is easy to figure out. Write a prototype and ask a few rookies to try it out (or post it on Reddit). Ask them which part of the error message they registered (or registered first/best).

I'm sure there are a few usability experts at Mozilla. Maybe ask them?
(I think it would be pretty cool to have a small usability study on compiler error messages.)

@steveklabnik
Copy link
Member Author

That's not going to have a large enough sample size to matter.

(But yes, a big study would be nice.)

@vks
Copy link
Contributor

vks commented Aug 20, 2014

That's not going to have a large enough sample size to matter.

Still better than nothing?

@steveklabnik
Copy link
Member Author

I actually don't think so, as it gives you a veil of objectivity without actually being objective.

Anyway, it's a distraction, overall.

@vks
Copy link
Contributor

vks commented Aug 20, 2014

Well, of course it won't be objective, that is not really the aim. I thought it might cover more potential rookie-pitfalls than just speculating.

@Gankra
Copy link
Contributor

Gankra commented Aug 20, 2014

Digging through how this stuff is set up now. All the diagnostic messages are defined in a single file as raw strings in src/librustc/diagnostis.rs. They're registered with some family of macros, which are themselves full-on plugins(!).

That doesn't strike me as a particularly scalable solution if each one of these is going to be a huge discussion of the error. However I'm not sure if there's a technical reason for this, or if this was just convenient/reasonable at the time. Not sure why this had to be done as a macro/plugin either.

A saner alternative might be to just provide the path to the error md, and have them parsed in as plain text, with the #Summary header stripped and everything after the next header (\n# I guess?) excluded. However I'm not clear as to what can or can't be done in librustc's code, especially if things need to be available at early stages of compilation.

However, with this design librustc and librustdoc don't really need to know about each other, they just both know about these docs. Librustc does gain a minor understanding of markdown (in that it knows #'s at starts of lines are important), and the first section of the docs will have to be fairly more well-formed than other doc pages, but not by much.

@alexcrichton
Copy link
Member

ping @steveklabnik, is this ready to go?

@aturon
Copy link
Member

aturon commented Oct 17, 2014

re-ping @steveklabnik

This error occurs when it's impossible for a particular `match` arm to ever
match the given pattern, because one of the preceeding arms will match.

This means that perhaps some of the preceeding patterns are too general, this
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/preceeding/preceding/

# Summary

This error occurs when it's impossible for a particular `match` arm to ever
match the given pattern, because one of the preceeding arms will match.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/preceeding/preceding/

@steveklabnik
Copy link
Member Author

@aturon it's unclear to me that there's any kind of consensus about what the output should be, with and without the flag. If we can make that decision, I'll happily get this ready to merge.

bors added a commit that referenced this pull request Oct 17, 2014
This adds ‘help’ diagnostic messages to rustc. This is used for anything that provides help to the user, particularly the `--explain` messages that were previously integrated into the relevant error message.

They look like this:

```
match.rs:10:13: 10:14 error: unreachable pattern [E0001]
match.rs:10             1 => {},
                        ^
match.rs:3:1: 3:38 note: in expansion of foo!
match.rs:7:5: 20:2 note: expansion site
match.rs:10:13: 10:14 help: pass `--explain E0001` to see a detailed explanation
```

(`help` is coloured cyan.) Adding these errors on a separate line stops the lines from being too long, as discussed in #16619.
@vks
Copy link
Contributor

vks commented Oct 17, 2014

@steveklabnik I think there was some consensus that the message is currently too long.

I would be fine with moving the link to the --explain output or at least breaking the super long line, for instance like this:

steve@computer:~/tmp$ rustc hello.rs 
hello.rs:4:9: 4:10 error: unreachable pattern [E0001]
                   (pass `--explain E0001` or visit http://doc.rust-lang.org/errors/E0001.html for more detail)
hello.rs:4         7       => (),
                   ^
error: aborting due to previous error

@nikomatsakis
Copy link
Contributor

💃 just want to show my general delight to see motion on this

@alexcrichton
Copy link
Member

Closing due to inactivity (and @bors's queue is quite full!) Feel free to reopen with a rebase!

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.