diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2023-10-21 13:08:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-21 13:08:28 -0400 |
| commit | a296ab9796f4452dd4327b6593254848319fb894 (patch) | |
| tree | b792b6bd2bf139e84619c871e7cf8192746b83ca /cmd | |
| parent | 0bc5ad4b6c59e0bd4a86f32342bf0c82f01f7877 (diff) | |
Remove defers from main() to stop suppressing panics (#1851)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'cmd')
| -rw-r--r-- | cmd/gomplate/main.go | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/cmd/gomplate/main.go b/cmd/gomplate/main.go index 7cc37162..17caa9e2 100644 --- a/cmd/gomplate/main.go +++ b/cmd/gomplate/main.go @@ -11,16 +11,15 @@ import ( ) func main() { - exitCode := 0 - // defer the exit first, so it executes last, to let the deferred cancel run - defer func() { os.Exit(exitCode) }() + if err := run(); err != nil { + os.Exit(1) + } +} +func run() error { ctx, cancel := context.WithCancel(context.Background()) defer cancel() // need to strip os.Args[0] so we only pass the actual flags - err := cmd.Main(ctx, os.Args[1:], os.Stdin, os.Stdout, os.Stderr) - if err != nil { - exitCode = 1 - } + return cmd.Main(ctx, os.Args[1:], os.Stdin, os.Stdout, os.Stderr) } |
