Open cthulhu-rider opened 3 weeks ago
I'd just use RunE
and move ExitOnErr
code-related logic to main
.
RunE
's problem (and i agree with it): https://github.com/nspcc-dev/neofs-node/issues/623.
RunE
's problem (and i agree with it): #623.
silencers prevent this as in code example
some
Cobra
-based programs exit instantly on particular errors:they call
os.Exit
due to which neither cmd postruns, nor finalizers, nor even execdefer
funcs are called. The latter are usually responsible for allocating resources such as network connections, files, etc.Steps to Reproduce
cmd/neofs-test/main.go
$ ./bin/neofs-test in defer in PostRun in PersistentPostRun in finalizer err: any error $ echo $? 1
$ ./bin/neofs-test err: any error $ echo $? 1
2. Specific error +
RunE
+ unsupported*PostRun
the most correct solution to me in terms of
os.Exit
, but narrows the breadth of cmd lifetime use. Also requires a lot of changes but code will look less "spaghetti"3. Fake
defer
's + unsupported*PostRun
the worst to me but fast solution requiring less changes
Context
Cobra itself has no in-box mechanism to work with OS exit codes, only similar funcs
ive been hiding this topic in myself for a long time, but now im ready to present it
Regression
no
Your Environment
neofs-cli@v0.42.1