top | item 12263384

Shape of errors to come

425 points| runesoerensen | 9 years ago |blog.rust-lang.org | reply

161 comments

order
[+] cfallin|9 years ago|reply
I really appreciate the user-friendliness of Rust's error messages -- I can't remember seeing a compiler tell me "maybe try this instead?" before (perhaps something from Clang, but never with the specificity of, e.g., a suggested lifetime annotation). And from a parsing / compiler-hacking perspective, it seems really hard to get the heuristics good enough to produce the "right" root cause. Kudos to the Rust team for this continued focus!
[+] jerf|9 years ago|reply
It's taken... I dunno, 50+ years?... but it's nice to see more and more code being written that doesn't assume programmers are superhuman beings with an IQ of 250 and infinite concentration and working memory. We need all the help we can get, so that we can focus as much of our precious, limited cognitive firepower on what really matters. When even John Carmack is talking about getting all the help he can from his development environment [1], you really ought to listen.

[1]: http://number-none.com/blow/john_carmack_on_inlined_code.htm...

[+] tetrep|9 years ago|reply
Haskell has gotten really good at more or less telling you what to do, it's a pretty common technique while developing to have the compiler run in the background whenever you change a file[0]. I've found it to be great when developing because you can just let the compiler tell you what type you need to put somewhere, and you can use something like Hoogle[1] to find how you can get that type.

[0]: usually people use this: http://www.mew.org/~kazu/proj/ghc-mod/en/ghc-modi.html

[1]: http://hoogle.haskell.org/

[+] ams6110|9 years ago|reply
In OpenBSD you'll see stuff like:

warning: stpcpy() is dangerous GNU crap; don't use it

warning: strcpy() is almost always misused, please use strlcpy()

warning: strcat() is almost always misused, please use strlcat()

warning: sprintf() is often misused, please use snprintf()

[+] fizzbatter|9 years ago|reply
I'm quite new to a lot of the concepts in Rust, and while many error messages are simply infuriatingly confusing.. there are many that are extremely helpful.

Hell, just the underline showing you what area is wrong really helps you spend the fewest cycles on simple typos and etc. It's really a joy.

Fwiw, the frustrating times are usually involving some semi-obscure type system issue i've caused. But seeing as i'm probably their target user for these sort of messages (beginner), i guess my issues are still probably relevant.

[+] kalleboo|9 years ago|reply
I don't know if I've seen it in compiler output, but I've seen IDEs like Eclipse and XCode have some pretty good "fix it for me" suggestions (maybe those are sourced from the compiler, I'm not sure).
[+] taeric|9 years ago|reply
The jikes java compiler had very well done error messages, from what I remember.
[+] justinsaccount|9 years ago|reply
In my little rust experience the suggestions the error messages had, even in the longer explanations, were useless. Mostly it came down to me trying to do something that was simply not supported, but the compiler not knowing that and leading me on a wild goose chase.

From what I remember, I was trying to use the iterator trait, but return records that contained str pointers.. The goal being to parse a file and yield pointers to the strings from each line to avoid allocating memory and copying bytes around. Rust tries to tell you that you need lifetime specifiers, but if you try adding those nothing compiles anyway because the iterator stuff doesn't actually support that.

I eventually got it to work by returning copies of the strings.. maybe the unsafe stuff would have done what I wanted, that's what rust-csv seems to do at least.

I concluded that Rust is definitely not a language you can learn by chasing down error messages and incrementally fixing things. If you don't 100% understand the borrow and lifetime stuff, fixing one error is just going to cause two new ones.

[+] steveklabnik|9 years ago|reply
Hm, iterators can definitely return pointers. Post on users.rust-lang.org or drop by IRC sometime! We're happy to help.
[+] dllthomas|9 years ago|reply
Please put file locations (as many as might be relevant) at the start of a line in the standard format!

The other changes look valuable. Improving error reporting is great.

Edited to add emphasis: I really did mean a line, not every line.

[+] pcwalton|9 years ago|reply
Those file locations repeated every line accounted for a lot of the noise in the previous format. I'm glad they're gone.
[+] waynenilsen|9 years ago|reply
I would love to see an option for showing the error order forward or backward. My workflow is to start fixing compile time errors from the top of the `cargo` output but scrolling to the top can be fairly annoying when there are a lot of errors. Having the most relevant error at the bottom of the command line (where it automatically scrolls) would be useful as an option IMO. This probably causes some other unseen problems however
[+] klodolph|9 years ago|reply
I find it's much easier to use editor integration to do this, rather than opening a separate terminal window to compile.
[+] ansible|9 years ago|reply
Well, I just use 'more' or 'less' to see the beginning of the output. I'm also using GNU screen, and can easily scroll back through the terminal's history if I can't be bothered to re-run the command with a pager on the output.
[+] gnuvince|9 years ago|reply
Very good! I always liked the content of Rust's error messages as it clearly explained the issue, but the form of those error messages was a bit problematic, they were very noisy and it wasn't easy to see the issue by simply glancing, you had to scroll up, find the beginning of the error and read carefully.
[+] karysto|9 years ago|reply
I always love it when we bring UX to the the tooling we use, and not just on the end product in our users' hands. Everyone appreciates a delightful UX, including software engineers. I've been eyeing Rust for a while now, this just gives me another excuse to hack with it.
[+] ColinDabritz|9 years ago|reply
I love the clarity and readability of these errors. You can work on UX at lower levels, and it looks like this. Beautiful. I'm not even a Rust dev, I'm mostly in C# land these days, but I appreciate the effort this takes. Well done!
[+] Animats|9 years ago|reply
Imagine what you could do if error messages didn't have to appear as plain text. You could have arrows, lines, shaded areas, and even multiple fonts.
[+] kibwen|9 years ago|reply
Every error has a JSON representation, which any tool can receive and display it whatever way it chooses.
[+] taneq|9 years ago|reply
What would this gain us, other than visual clutter and compatibility issues between IDEs?
[+] zalmoxes|9 years ago|reply
Inspired by Elm?
[+] squiguy7|9 years ago|reply
Yes, here is a quote from the post:

> Those of you familiar with the Elm style may recognize that the updated --explain messages draw heavy inspiration from the Elm approach.

[+] alexbock|9 years ago|reply
Elm inspiration is mentioned at the end of the "Extended error messages" section.
[+] jweir|9 years ago|reply
I've been working with Elm over the last week, and the error messages are informative and helpful. When, possible they educate you on the nature of the error and guide you on how to fix the problem.
[+] IshKebab|9 years ago|reply
This is great! Why keep the row/column numbers at the end of the source file though? Aren't they redundant (IDEs shouldn't be parsing command line output anyway so they don't need it).
[+] nneonneo|9 years ago|reply
This focus on compiler usability is really fantastic. C calls these "compiler diagnostics" for a reason - they should help the programmer diagnose and fix the problem. I loved it when Clang started making C errors sane (and getting GCC to introduce better messages too!), and I'm glad to see Rust take the next step. Since I'm stuck in C++ for the time being, I'm (selfishly) hoping that Clang takes a page from these new Rust errors - these sorts of diagnostics would look great on C++!
[+] marsrover|9 years ago|reply
Not related to this article, but I was looking through the Rust survey mentioned at the bottom of the article and was surprised at the amount of people using it for web development.

I'm not very knowledgeable about Rust but I guess I assumed it would not be the best technology to use in that space. Is Rust really that prevalent in web development?

[+] fizzbatter|9 years ago|reply
That's mainly my goal as i learn Rust. It's been a difficult learning process[1], but i persist because the code i write feels simply more correct. I also think as time goes on frameworks will improve the ease of use, much of the ecosystem is very young.

Even better (or more crazy, heh), i plan on using Rust for clientside as soon as we have a feasible Rust -> DOM api bridge.

[1]: My learning process was mainly involved in the type system, when writing my own libraries. Not so much to do with basic web development.

[+] nfriedly|9 years ago|reply
I think part of it is just because there are a lot of people doing web development.

Also, of that group of people, many of us like to try out new things even if they aren't the best match...

[+] steveklabnik|9 years ago|reply
crates.io, for example, has Rust on the backend. There's a HN poster who uses Rust server-side for his business, IRC.

https://news.ycombinator.com/item?id=10312354 is a comment I made a while back about it. I've gone from "why would you do that" to "this can make sense, depending" over the years.

[+] mrich|9 years ago|reply
Great to see an improvement over the already improved error reporting established by clang and later adopted by gcc.

However I don't understand why backticks are still being used - they tend to look ugly especially when pasting them into emails etc.

[+] kibwen|9 years ago|reply
Backticks aren't used anywhere in the language itself so they're an obvious choice for a delimiter, and such usage has been popularized by markdown.
[+] Symmetry|9 years ago|reply
That looks really cool and I'll have to give learning Rust another try when this lands. Also, the title was pretty wonderful. I spent a bit thinking about it before looking at the domain and realizing what it had to be.
[+] knodi|9 years ago|reply
damn... thats nice. Can't wait to dive into it.
[+] hyperpape|9 years ago|reply
Do I understand correctly that since this is in the current nightlies, it's slated for 1.12? So, sometime in October?
[+] steveklabnik|9 years ago|reply
Yes, current nightlies are 1.12. Anything can happen before release, though, so in theory, it's not guaranteed to land in 1.12 until the day that 1.12 forks off from master.