unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.81k stars 271 forks source link

There should be a way to exit with a non-zero exit code #5398

Open TOGoS opened 1 month ago

TOGoS commented 1 month ago

Is your feature request related to a problem? Please describe.

As far as I am aware, there is no way to have a Unison program exit with a specified exit code.

Describe the solution you'd like

My preference would be to have main-like functions return an integer, since that allows for composable mains (as opposed to something like an unhandleable IO.exit effect). Having a 'set exit code' or 'quit now with exit code' be part of the IO ability would also be acceptable. Or a special type of Failure. Or a new ability. Maybe call it Quit Int.

It is the kind of thing I often want to handle, though, because I don't necessarily want to force the OS process to quit. e.g. just because my program does an exit 1 doesn't mean I want ucm.exe to stop. What I want is not so much about stopping the process as providing an exit code from main, which if it happens to be the top-level function, should cause the containing process to exit with the code I gave.

/me grumbles about always writing wrapper functions to avoid writing System.exit(1)

Describe alternatives you've considered

Current workaround is to throw an exception. This doesn't allow for exit codes other than 0 (return normally) or 1 (throw exception), and results in Unison printing out some additional information that I didn't necessarily want to show.

Additional context

image

(from a little proof-of-concept program)