You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is fairly easy for an external project to call this function and have unexpected results in their program because they were not anticipating a library they were using to call os.Exit().
The only place within the Zarf project calling Execute() is within main.go.
I would like to propose having Execute() return an int or an err and let the calling main() perform the os.Exit().
After writing this out, I realize I am asking for a breaking change, since this will change the function signature of Execute, so I won't be sad at all if the team decides to just disregard this request.
The text was updated successfully, but these errors were encountered:
YrrepNoj
changed the title
Tech Debt Request: Avoid calling os.Exit() is exported functions
Tech Debt Request: Avoid calling os.Exit() in exported functions
Feb 20, 2025
@YrrepNoj I would agree that it makes sense to call os.Exit in main rather than in a package. However, if we introduced a breaking change here, I'd rather make cmd.Execute private, and instead encourage users to call the function NewZarfCommand() to either embed Zarf directly with cmd.AddCommand(cmds ...*Command) or by calling NewZarfCommand().ExecuteContextC(ctx) when not using Cobra. All cmd.Execute does is log the error and exit.
If NewZarfCommand works for you, I can spin up a PR with those changes
Zarf has a publicly accessible function src/cmd/root.go -> Execute() that calls
os.Exit()
.It is fairly easy for an external project to call this function and have unexpected results in their program because they were not anticipating a library they were using to call
os.Exit()
.The only place within the Zarf project calling Execute() is within main.go.
I would like to propose having
Execute()
return anint
or anerr
and let the callingmain()
perform theos.Exit()
.After writing this out, I realize I am asking for a breaking change, since this will change the function signature of Execute, so I won't be sad at all if the team decides to just disregard this request.
The text was updated successfully, but these errors were encountered: