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()
129 } else {
130 printError(err.Error())
131 }
132 os.Exit(1)133}
134
135func printError(text string) {
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
133 }
134
135 waitStatus := cmd.ProcessState.Sys().(syscall.WaitStatus)
136 os.Exit(waitStatus.ExitStatus())137 return nil
138}
139
621 if err != nil {
622 fmt.Println(aurora.Red("AWS Session Manager plugin was not found on the path. Install it locally to use this feature."))
623 fmt.Println(aurora.White("https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html"))
624 os.Exit(1) 625 }
626 region := a.Session.Config.Region
627 arg1, err := json.Marshal(ecsSession)
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.
func nonMainFunc() {
safelyExit := true // somehow arrive at this value
if safelyExit {
os.Exit(0)
}
}
func main() {
nonMainFunc()
}
func nonMainFunc() bool {
safelyExit := true // somehow arrive at this value
}
func main() {
safelyExit := nonMainFunc()
if safelyExit {
os.Exit(0)
}
}