Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors returned by subcommands are ignored by ExitErrHandler #736

Closed
roobre opened this issue Apr 15, 2018 · 5 comments
Closed

Errors returned by subcommands are ignored by ExitErrHandler #736

roobre opened this issue Apr 15, 2018 · 5 comments

Comments

@roobre
Copy link

roobre commented Apr 15, 2018

When a subcommand receiver outputs an error, app.ExitErrHandler is not called.

func main() {
	app := cli.NewApp()
	app.Commands = []cli.Command{
		{
			Name:        "firstlevel",
			Action:      firstlevel,
		},
		{
			Name:        "parent",
			Subcommands: []cli.Command{
				{
					Name:        "sub1",
					Action:      sub1,
				}, {
					Name:        "sub2",
					Aliases: []string{"d"},
					Action:      sub2,
				},
			},
		},
	}

	app.ExitErrHandler = func(context *cli.Context, err error) {
		fmt.Println(err)
	}

	app.Run(os.Args)
}

// [...] all receivers return an error for this example

When an error is returned on firstlevel firstlevel(), it gets printed. However, if either sub1 or sub2 return it it is not. Not sure if this is a bug or I'm trying to do some weird things, but some insights would be appreciated anyway :)

@travisperson
Copy link

I believe it's a bug. Subcommands are basically recursive apps, and are setup through command#startApp., which appears to not copy the ExitErrHandler function over.

travisperson added a commit to travisperson/cli that referenced this issue Jul 25, 2018
Errors returned by subcommands no longer bypass the toplevel ExitErrHandler

Fixes urfave#736
@jkanywhere
Copy link

AppVeyer build is failing go vet failure which is also in master.

python runtests vet
45# github.com/urfave/cli
46.\command_test.go:328:3: value declared but not used
47vet: typecheck failures
48runtests: go vet ./...
...

@jkanywhere
Copy link

I opened #763 to address the go vet error.

travisperson added a commit to travisperson/cli that referenced this issue Aug 23, 2018
Errors returned by subcommands no longer bypass the toplevel ExitErrHandler

Fixes urfave#736
@coilysiren
Copy link
Member

Given that this is from last year, I think I'm comfortable closing it 🙂 feel free to re-open / open a new issue / comment in support if there's still interest here!

@coilysiren
Copy link
Member

A fix for this was merged here => #856

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants