Ensures exit with error code if actionFunc returns an error
(actionFunc cli.ActionFunc)
| 23 | |
| 24 | // Ensures exit with error code if actionFunc returns an error |
| 25 | func WithErrorHandler(actionFunc cli.ActionFunc) cli.ActionFunc { |
| 26 | return func(ctx *cli.Context) error { |
| 27 | err := actionFunc(ctx) |
| 28 | if err != nil { |
| 29 | if _, ok := err.(usageError); ok { |
| 30 | msg := fmt.Sprintf("%s\nSee 'cloudflared %s --help'.", err.Error(), ctx.Command.FullName()) |
| 31 | err = cli.Exit(msg, -1) |
| 32 | } else if _, ok := err.(cli.ExitCoder); !ok { |
| 33 | err = cli.Exit(err.Error(), 1) |
| 34 | } |
| 35 | } |
| 36 | return err |
| 37 | } |
| 38 | } |
no test coverage detected