Skip to content

Commit

Permalink
chore: log failure to run CLI command (#12863)
Browse files Browse the repository at this point in the history
Log failure to run CLI command

Prior code only conditionally logged the output when `LOTUS_DEV` env
var was present. This doesn't make sense for a number of reasons:

* In case of an error starting up `lotus daemon` via systemctl for
  example the logs would miss the error. One then has to search through
  system journal to see what happened.

* There are no other places that I can find where `LOTUS_DEV` env var is
  used. The commit that introduced this condition is very old with no
  clear commit message to shed light into the rationale.

For the first reason alone, the changes here remove that condition, and
log the message when the logging output is not standard err or out. This
way we at least cover the case where lotus is run in a production
environment and would avoid partial logging of errors.
  • Loading branch information
masih authored Feb 4, 2025
1 parent e4ea131 commit bb70977
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions cli/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"os/signal"
"syscall"

logging "github.com/ipfs/go-log/v2"
ufcli "github.com/urfave/cli/v2"
)

Expand Down Expand Up @@ -46,11 +47,13 @@ func RunApp(app *ufcli.App) {
}()

if err := app.Run(os.Args); err != nil {
if os.Getenv("LOTUS_DEV") != "" {
log.Warnf("%+v", err)
} else {
fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err) // nolint:errcheck
if cfg := logging.GetConfig(); !(cfg.Stdout || cfg.Stderr) {
// To avoid printing the error twice while making sure that log file contains the
// error, check the config and only print it if the output isn't stderr or
// stdout.
log.Errorw("Failed to start application", "err", err)
}
_, _ = fmt.Fprintf(os.Stderr, "ERROR: %s\n\n", err)
var phe *PrintHelpErr
if errors.As(err, &phe) {
_ = ufcli.ShowCommandHelp(phe.Ctx, phe.Ctx.Command.Name)
Expand Down

0 comments on commit bb70977

Please sign in to comment.