Closed emizzle closed 1 year ago
There's a bug in Results
for catch
fixed here: https://github.com/status-im/nim-stew/pull/201
with that fix, you can do the following with plain results:
import stew/results
proc returnsVoid =
raise newException(ValueError, "some error")
catch(returnsVoid()).isOkOr:
echo "error: ", error.msg
Not sure if the chaining syntax can be made to work..
I tried @emizzle's example with the latest stew
and latest results
, and it still doesn't compile. But if we get rid of the chaining syntax as @arnetheduck suggested, then it does work:
import pkg/questionable
proc returnsVoid =
raise newException(ValueError, "some error")
if err =? catch(returnsVoid()).errorOption:
echo "failed to do something, error: ", err.msg
I think that this is simply one of the limitations of the method call syntax.
I could possibly be doing something wrong, but I have run into situations where I'd like to chain
.catch.errorOption
so that an error can be caught and turned into aResult[void, CatchableError]
, but this isn't allowed because the called proc returns a void. For example, this doesn't compile: