codex-storage / questionable

Elegant optional types for Nim
Other
116 stars 5 forks source link

Add `$`(ResultFailure e) = e.msg #15

Closed Bulat-Ziganshin closed 1 year ago

Bulat-Ziganshin commented 2 years ago

When we have x : ?!T and use x.expect(...), we don't see x.e.msg in the raised exception because this code tries to use $(x.e) which is undefined for ResultFailure

See example in https://github.com/status-im/nim-codex/pull/160#issuecomment-1201753390

markspanbroek commented 2 years ago

Yes, not having a $ for errors is annoying. I ran into this a while ago myself.

I tried adding the following to results.nim:

proc `$`*(error: ref CatchableError): string =
  error.msg

But this somehow breaks an unrelated test for catch.

Root cause seems to be this issue in nim-result.