In some circumstances, you may want to stop your program immediately without allowing any caller of the function to catch or handle the error. For that you can use the built in functionbase.bug
in Unison. UnlikeOptional
orEither
- if you callbase.bug
in a function, you do not need to represent the possibility of the failure in the function's signature as a data type for the caller to manage.
You can provide a term or expression of any type tobase.bug
and theUCMwill render that value to the console.
superProgram : Boolean -> Nat
superProgram bool =
if Boolean.not bool then
base.bug (Generic.failure "Fatal Issue Encountered" bool)
else 100
Calling the function above withsuperProgram false
will abort the running program with the message
💔💥
I've encountered a call to builtin.bug with the following value:
Failure (typeLink Generic) "Fatal Issue Encountered" (Any false)
🚩 Usebase.bug
judiciously, as there is currently no way for a program to recover from a call tobase.bug
.