Result
The Result
class indicates the success/failure of validation.
from exacting import Result
# Success
Result.Ok("some value")
# Error
Result.Err(
"You bad",
"literally"
)
Is OK?
This checks if the validation result is OK.
Raising
Result
can help you raise a ValidationError
if errors are present.
Unwrapping
You can get the data that got through the validation by unwrapping, or the error messages.
ok = Result.Ok(-123)
print(ok.unwrap()) # -123
err = Result.Err("be be nos")
print(err.unwrap_err()) # deque(['be be nos'])
Trace
You can trace errors down using the trace()
function, making previous errors appear indented.
base_err = Result.Err("Gustavo Fring")
(
base_err
.trace("Woah, there's a gustavo down here")
.trace("Breaking bad!")
.raise_for_err()
)
ValidationError: Breaking bad!
Trace below
Make other errors appear indented below your message.