Skip to content

Instantly share code, notes, and snippets.

@carlpett
Created August 29, 2018 06:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlpett/bc1714060235edc0ad3fd9ead82f4ce6 to your computer and use it in GitHub Desktop.
Save carlpett/bc1714060235edc0ad3fd9ead82f4ce6 to your computer and use it in GitHub Desktop.

Many programs will be outputting the their errors directly onto stdout/stderr, and then ingesting these logs with some form of log aggregation tool (Logstash/Splunk/...). With multi-line errors, this requires configuring these tools to recognize log entries spanning multiple lines. To make this easier, it might make sense to have a common prefix on all following lines, rather than alternating spaces and triple-dash as in the examples:

write users database:
    more detail here
    /path/to/database.go:111
--- call myserver.Method:
    /path/to/grpc.go:222
--- dial myserver:3333:
    /path/to/net/dial.go:333
--- open /etc/resolv.conf:
    /path/to/os/open.go:444
--- permission denied

It might still make sense to mark where one wrapped error begins and ends, but having some marker that is simple and consistent would make running Go 2 programs in environments with log collection easier.

@mpvl
Copy link

mpvl commented Nov 6, 2018

There are multiple way about this.

  1. People could implement their own Printer that uses alternative formatting, e.g. some structured format.
  2. We could consider using some of the printf flags to suggest an alternative format.
  3. Make 2 the default.

For instance "% +v" could print 2 or so extra space on each subsequent line:

write users database:
      more detail here
      /path/to/database.go:111
  --- call myserver.Method:
      /path/to/grpc.go:222
  --- dial myserver:3333:
      /path/to/net/dial.go:333
  --- open /etc/resolv.conf:
      /path/to/os/open.go:444
  --- permission denied

or

write users database:
    more detail here
    /path/to/database.go:111
  * call myserver.Method:
    /path/to/grpc.go:222
  * dial myserver:3333:
    /path/to/net/dial.go:333
  * open /etc/resolv.conf:
    /path/to/os/open.go:444
  * permission denied

@mpvl
Copy link

mpvl commented Nov 6, 2018

@ansidhe
Copy link

ansidhe commented Mar 19, 2022

Hi,

I realise it may be far too late to submit my comment or you may find it way too trivial but in case you did find it as adding value, I highly recommend taking a look at how Evan Czaplicki implemented error messages in Elm:
https://elm-lang.org/news/compiler-errors-for-humans
https://elm-lang.org/news/compilers-as-assistants
https://elm-lang.org/news/the-syntax-cliff

When searching for the source of inspiration that Evan had drawn from, I found that Rust's error messages were apparently inspired by his work on Elm's ones:
https://blog.rust-lang.org/2016/08/10/Shape-of-errors-to-come.html

That would slightly reduce my doubt regarding the different general possibilities that you might be facing when designing error message mechanisms for a backend language as opposed to a frontend lang like Elm. After all I have read in your drafts about your looking for inspirations, best practices and "peer comparisons" in how Rust handles things, including errors.

Another interesting take on the topic of error messages:
https://calebmer.com/2019/07/01/writing-good-compiler-error-messages.html

And a somewhat humorous one (albeit still partially informative between the lines):
https://www.reddit.com/r/haskell/comments/54l3ug/readable_error_messages_like_in_elm/

Thank you for your great work, I cannot wait to see Go2 :)!

Best wishes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment