From 3508a5b664fce10d121872edd16a59729d4e1f3c Mon Sep 17 00:00:00 2001 From: Mike Greenberg Date: Fri, 17 Sep 2021 18:01:54 -0400 Subject: [PATCH] chore: Use After hooks and proper args --- cli/helper.go | 8 -------- cmd/lotus-miner/main.go | 14 ++++++++++++++ cmd/lotus-seal-worker/main.go | 14 ++++++++++++++ cmd/lotus/main.go | 14 ++++++++++++++ 4 files changed, 42 insertions(+), 8 deletions(-) diff --git a/cli/helper.go b/cli/helper.go index 71a2268c6..da236bcae 100644 --- a/cli/helper.go +++ b/cli/helper.go @@ -5,7 +5,6 @@ import ( "io" "os" - "github.com/filecoin-project/lotus/build" ufcli "github.com/urfave/cli/v2" "golang.org/x/xerrors" ) @@ -33,13 +32,6 @@ func ShowHelp(cctx *ufcli.Context, err error) error { } func RunApp(app *ufcli.App) { - defer func() { - if r := recover(); r != nil { - // Generate report in LOTUS_PATH and re-raise panic - build.GeneratePanicReport(os.Getenv("LOTUS_PATH"), "app_panic") - panic(r) - } - }() if err := app.Run(os.Args); err != nil { if os.Getenv("LOTUS_DEV") != "" { log.Warnf("%+v", err) diff --git a/cmd/lotus-miner/main.go b/cmd/lotus-miner/main.go index 954a958b6..b7800013c 100644 --- a/cmd/lotus-miner/main.go +++ b/cmd/lotus-miner/main.go @@ -113,6 +113,12 @@ func main() { Usage: "use color in display output", DefaultText: "depends on output being a TTY", }, + &cli.StringFlag{ + Name: "panic-reports", + EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"}, + Hidden: true, + Value: "~/.lotus", // should follow --repo default + }, &cli.StringFlag{ Name: "repo", EnvVars: []string{"LOTUS_PATH"}, @@ -146,6 +152,14 @@ func main() { } return nil }, + After: func(c *cli.Context) error { + if r := recover(); r != nil { + // Generate report in LOTUS_PATH and re-raise panic + build.GeneratePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name) + panic(r) + } + return nil + }, } app.Setup() app.Metadata["repoType"] = repo.StorageMiner diff --git a/cmd/lotus-seal-worker/main.go b/cmd/lotus-seal-worker/main.go index adcf0f869..da557ad61 100644 --- a/cmd/lotus-seal-worker/main.go +++ b/cmd/lotus-seal-worker/main.go @@ -75,6 +75,12 @@ func main() { Value: "~/.lotusworker", // TODO: Consider XDG_DATA_HOME Usage: fmt.Sprintf("Specify worker repo path. flag %s and env WORKER_PATH are DEPRECATION, will REMOVE SOON", FlagWorkerRepoDeprecation), }, + &cli.StringFlag{ + Name: "panic-reports", + EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"}, + Hidden: true, + Value: "~/.lotus", // should follow --repo default + }, &cli.StringFlag{ Name: "miner-repo", Aliases: []string{"storagerepo"}, @@ -89,6 +95,14 @@ func main() { }, }, + After: func(c *cli.Context) error { + if r := recover(); r != nil { + // Generate report in LOTUS_PATH and re-raise panic + build.GeneratePanicReport(c.String("panic-reports"), c.String(FlagWorkerRepo), c.App.Name) + panic(r) + } + return nil + }, Commands: local, } app.Setup() diff --git a/cmd/lotus/main.go b/cmd/lotus/main.go index 66eae0f1e..7aa2e704e 100644 --- a/cmd/lotus/main.go +++ b/cmd/lotus/main.go @@ -67,6 +67,12 @@ func main() { Version: build.UserVersion(), EnableBashCompletion: true, Flags: []cli.Flag{ + &cli.StringFlag{ + Name: "panic-reports", + EnvVars: []string{"LOTUS_PANIC_REPORT_PATH"}, + Hidden: true, + Value: "~/.lotus", // should follow --repo default + }, &cli.StringFlag{ Name: "repo", EnvVars: []string{"LOTUS_PATH"}, @@ -84,6 +90,14 @@ func main() { }, cliutil.FlagVeryVerbose, }, + After: func(c *cli.Context) error { + if r := recover(); r != nil { + // Generate report in LOTUS_PATH and re-raise panic + build.GeneratePanicReport(c.String("panic-reports"), c.String("repo"), c.App.Name) + panic(r) + } + return nil + }, Commands: append(local, lcli.Commands...), }