News for hackers. Stuff that matters.
Re:Errors are values by skybrian on Tuesday January 13, 2015 @01:14AM (#8878438)
Maybe is not an error-handling mechanism because it doesn't report any error message. I don't know why Haskell programmers think it's any good for reporting errors.

You could use Either, but it doesn't give you any guarantee that you'll get a string back, and the naming is lousy. (Left and Right? Really? I know there's a mnemomic, but we can do better than that.)

So, might as write your own ADT and name it right.

(Also, a real error-reporting mechanism should support cause chaining so you can see the dependencies; you can sort of do it with string concatenation but it gets awkward after a few levels.)

Re:Errors are values by masklinn on Tuesday January 13, 2015 @04:13AM (#8878784)
> So, might as write your own ADT and name it right.

http://doc.rust-lang.org/std/result/enum.Result.html

> (Also, a real error-reporting mechanism should support cause chaining so you can see the dependencies; you can sort of do it with string concatenation but it gets awkward after a few levels.)

http://doc.rust-lang.org/std/error/trait.Error.html

Either isn't custom-built for error reporting, so it makes sense that its naming only conventionally matches.

Re:Errors are values by codygman on Tuesday January 13, 2015 @01:45AM (#8878493)
> You could use Either, but it doesn't give you any guarantee that you'll get a string back

1. It's better not to use strings and instead use a user defined error type. 2. What do you mean "doesn't give you any guarantee you'll get a string back"?

> real error-reporting mechanism should support cause chaining so you can see the dependencies;

Can you elaborate on cause chaining, perhaps with an example?

Re:Errors are values by skybrian on Tuesday January 13, 2015 @04:06AM (#8878765)
What I mean is something like a stack trace except without all the extra detail:

  - Can't persist shopping cart
  - RPC request failed: http://example.com/update_cart
  - Can't write to database "carts"
  - Can't save file: "/a/b/c"
  - OS error: disk full
Ideally, all errors in the cause chain should be logged, and they typically cross abstraction boundaries; the message at each level comes from a different part of the stack. This seems hard to do across languages, but within a language there should be a standard way to do it.

(Go falls down on this too. Perhaps we don't need Java-style stack traces that go on for multiple screens, but we should have more than a string.)

Re:Errors are values by nbevans on Tuesday January 13, 2015 @01:59AM (#8878529)
Maybe is just an example. If you need to return more error codes, perhaps with contextual information such as message(s), then just define your own discriminated union and use that.