mirror of
https://github.com/status-im/nim-stew.git
synced 2025-01-09 11:45:42 +00:00
results: include error when expecting (#76)
This commit is contained in:
parent
6d3e6a21ca
commit
a0e8ec451e
@ -536,10 +536,10 @@ func `$`*(self: Result): string =
|
|||||||
func error*[T, E](self: Result[T, E]): E =
|
func error*[T, E](self: Result[T, E]): E =
|
||||||
## Fetch error of result if set, or raise Defect
|
## Fetch error of result if set, or raise Defect
|
||||||
if self.o:
|
if self.o:
|
||||||
when T is not void:
|
when T isnot void:
|
||||||
raiseResultDefect("Trying to access error when value is set", self.v)
|
raiseResultDefect("Trying to access error when value is set", self.v)
|
||||||
else:
|
else:
|
||||||
raise (ref ResultDefect)(msg: "Trying to access error when value is set")
|
raiseResultDefect("Trying to access error when value is set")
|
||||||
self.e
|
self.e
|
||||||
|
|
||||||
template value*[T, E](self: Result[T, E]): T =
|
template value*[T, E](self: Result[T, E]): T =
|
||||||
@ -628,7 +628,10 @@ template unsafeGet*[E](self: Result[void, E]) =
|
|||||||
|
|
||||||
func expect*[E](self: Result[void, E], msg: string) =
|
func expect*[E](self: Result[void, E], msg: string) =
|
||||||
if not self.o:
|
if not self.o:
|
||||||
raise (ref ResultDefect)(msg: msg)
|
when E isnot void:
|
||||||
|
raiseResultDefect(msg, self.e)
|
||||||
|
else:
|
||||||
|
raiseResultDefect(msg)
|
||||||
|
|
||||||
func `$`*[E](self: Result[void, E]): string =
|
func `$`*[E](self: Result[void, E]): string =
|
||||||
## Returns string representation of `self`
|
## Returns string representation of `self`
|
||||||
|
Loading…
x
Reference in New Issue
Block a user