calls to log.Fatal only in main() or init() functions
125func tempFilePath() string {
126 file, err := os.CreateTemp("", "")
127 if err != nil {
128 log.Fatal(err)129 }
130 os.Remove(file.Name())
131 return file.Name()
calls to os.Exit only in main() or init() functions
129 } else {
130 printError(err.Error())
131 }
132 os.Exit(1)133}
134
135func printError(text string) {
calls to os.Exit only in main() or init() functions
101 // run command
102 if err := rootCmd.Execute(); err != nil {
103 fmt.Println(err)
104 os.Exit(1)105 }
106
107 updateCancel() // if the update checker hasn't completed by now, abort it
calls to os.Exit only in main() or init() functions
133 }
134
135 waitStatus := cmd.ProcessState.Sys().(syscall.WaitStatus)
136 os.Exit(waitStatus.ExitStatus())137 return nil
138}
139
calls to os.Exit only in main() or init() functions
619 if err != nil {
620 fmt.Println(aurora.Red("AWS Session Manager plugin was not found on the path. Install it locally to use this feature."))
621 fmt.Println(aurora.White("https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html"))
622 os.Exit(1) 623 }
624 region := a.Session.Config.Region
625 arg1, err := json.Marshal(ecsSession)
Description
Packages exposing functions that can stop program execution by exiting are hard to reuse. Program exits in functions other than main() or init() are not encouraged.
Bad practice
func nonMainFunc() {
safelyExit := true // somehow arrive at this value
if safelyExit {
os.Exit(0)
}
}
func main() {
nonMainFunc()
}
Recommended
func nonMainFunc() bool {
safelyExit := true // somehow arrive at this value
}
func main() {
safelyExit := nonMainFunc()
if safelyExit {
os.Exit(0)
}
}