func actionWrapper(clientFactory *client.Factory, command func(context *cli.Context, client *client.Client) error) func(context *cli.Context) { return func(context *cli.Context) { cli, err := clientFactory.NewClient() if err != nil { stack.Print(err, os.Stderr, 0) os.Exit(1) } err = command(context, cli) if de, ok := err.(UsageError); ok { fmt.Fprintln(os.Stderr, de.Error()) os.Exit(1) } else if _, ok := err.(client.ConflictError); ok { os.Exit(1) } else if ade, ok := err.(client.AccessDeniedError); ok { fmt.Fprintln(os.Stderr, ade.Error()) os.Exit(1) } else if snfe, ok := err.(client.ServiceNotFoundError); ok { fmt.Fprintln(os.Stderr, snfe.Error()) os.Exit(1) } else if err != nil { stack.Print(err, os.Stderr, 0) os.Exit(1) } } }
func runDaemon(conf caretakerd.Config, args []string) { instance, err := caretakerd.NewCaretakerd(conf, sync.NewGroup()) if err != nil { stack.Print(err, os.Stderr, 0) os.Exit(1) } instance.Logger().Log(logger.Debug, caretakerd.DaemonName+" successful loaded. Starting now services...") exitCode, _ := instance.Run() instance.Logger().Log(logger.Debug, caretakerd.DaemonName+" done.") instance.Close() os.Exit(int(exitCode)) }
// HandlePanicOfPresent could be used as panic handler on top method like // defer panics.HandlePanicOfPresent(2) // ...to handle every panic in a better way. func HandlePanicOfPresent(framesToSkip int) { if r := recover(); r != nil { stack.Print(r, os.Stderr, 4+framesToSkip) os.Exit(2) } }
// DefaultPanicHandler could be used as panic handler on top method like // defer panics.DefaultPanicHandler() // ...to handle every panic in a better way. func DefaultPanicHandler() { if r := recover(); r != nil { stack.Print(r, os.Stderr, 4) os.Exit(2) } }