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

mockery exits successfully (exit code 0) if configuration is invalid #311

Closed
nmiyake opened this issue Jul 4, 2020 · 3 comments · Fixed by #312
Closed

mockery exits successfully (exit code 0) if configuration is invalid #311

nmiyake opened this issue Jul 4, 2020 · 3 comments · Fixed by #312

Comments

@nmiyake
Copy link
Contributor

nmiyake commented Jul 4, 2020

Add the entry zzz: aaa to .mockery.yaml and run mockery -- the application prints an error that indicates that decoding configuration failed, but still returns 0 to indicate a successful exit:

➜  mockery; echo $?
Using config file: /Volumes/git/go/src/github.com/vektra/mockery/.mockery.yaml
failed to get config: 1 error(s) decoding:

* '' has invalid keys: zzz
github.com/vektra/mockery/v2/cmd.GetRootAppFromViper
        /Volumes/git/go/src/github.com/vektra/mockery/cmd/mockery.go:130
github.com/vektra/mockery/v2/cmd.glob..func1
        /Volumes/git/go/src/github.com/vektra/mockery/cmd/mockery.go:33
github.com/spf13/cobra.(*Command).execute
        /Volumes/git/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:842
github.com/spf13/cobra.(*Command).ExecuteC
        /Volumes/git/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:950
github.com/spf13/cobra.(*Command).Execute
        /Volumes/git/go/pkg/mod/github.com/spf13/cobra@v1.0.0/command.go:887
github.com/vektra/mockery/v2/cmd.Execute
        /Volumes/git/go/src/github.com/vektra/mockery/cmd/mockery.go:59
main.main
        /Volumes/git/go/src/github.com/vektra/mockery/main.go:8
runtime.main
        /usr/local/go-1.14.4/src/runtime/proc.go:203
runtime.goexit
        /usr/local/go-1.14.4/src/runtime/asm_amd64.s:1373
0
@nmiyake
Copy link
Contributor Author

nmiyake commented Jul 4, 2020

This is due to the following code in cmd/mockery.go:

			r, err := GetRootAppFromViper(viper.GetViper())
			if err != nil {
				printStackTrace(err)
				return nil
			}

Changing the return nil to return err should resolve the issue. However, didn't open a PR for this since I'm not sure what the expected behavior is around stack traces -- this error check prints stack traces, but the r.Run() call does not, and the Execute call has it commented out. What is the desired behavior around printing stack traces for errors for this CLI? Once that is figured out, this can be properly fixed with consistency.

@LandonTClipp
Copy link
Contributor

Hey thanks for the find. This is indeed a mistake, simply returning the error here should be sufficient. It looks like I also missed the line here:

return r.Run()

That also needs to print the stack on errors. If you could send in a PR we'll get that merged right away!

nmiyake added a commit to nmiyake/mockery that referenced this issue Jul 6, 2020
@nmiyake
Copy link
Contributor Author

nmiyake commented Jul 6, 2020

Thanks -- opened #312 to address this specific issue of returning nil instead of the error. Will open a separate PR for the issue of the stack traces.

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.

2 participants