heroku / log-shuttle

HTTP log transport.

Home Page:log-shuttle.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

return error codes

freeformz opened this issue · comments

Opening this to have a convo with @fabiokung

Based on a conversation elsewhere ...

I don't understand what you mean by replacing those "Fatal(f) uses with returning errors at some point." That is how log-shuttle returns errors to the caller by using log.Fatalf(msg), which calls os.Exit(1). This returns a non-zero exit code to the calling program.

I mean:

func my() error {
    if err = doSomething(); err != nil {
        return err
    }
    // ...
}

Instead of:

func my() {
    if err = doSomething(); err != nil {
        log.Fatalf("....", err) // fmt.Fatal*, os.Exit, etc
    }
}

I'm personally not much a fan of *.Fatal* or other things that rely on os.Exit(). It doesn't allow other parts of the code to do proper cleanup (skips deferred functions) and/or recover from errors or do error handling. IMO even panic() would've been better. *.Fatal* is a last resort type of thing.

But that's just (my own?) code style. It's your call, don't sweat it too much.

For a library, I'm in total agreement with you.

And as I said elsewhere the only places log.Fatal get's used in to abort and exit as fast as possible during setup tasks.

Thanks for the thought our response though.