Bug--for aborting programs

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.bugin Unison. UnlikeOptionalorEither- if you callbase.bugin 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.bugand 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 falsewill 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.bugjudiciously, as there is currently no way for a program to recover from a call tobase.bug.