octolab / cli

💾 Toolkit for command line interfaces.
https://go.octolab.org/toolkit/cli
MIT License
0 stars 0 forks source link

custom error type with exit code #9

Closed kamilsk closed 3 years ago

kamilsk commented 3 years ago
func shutdown(err error) {
    code := 1
    if recovered, is := errors.Unwrap(err).(errors.Recovered); is {
        unsafe.DoSilent(fmt.Fprintf(stderr, "recovered: %+v\n", recovered.Cause()))
        unsafe.DoSilent(fmt.Fprintln(stderr, "---"))
        unsafe.DoSilent(fmt.Fprintf(stderr, "%+v\n", err))
    }
    if silent, is := errors.Unwrap(err).(errors.Silent); is {
        code = silent.code
        if silent.message { ... }
    }
    exit(code)
}