Skip to content

Configurable stack traces #15

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

Merged
merged 5 commits into from
Nov 28, 2018
Merged

Configurable stack traces #15

merged 5 commits into from
Nov 28, 2018

Conversation

yorinasub17
Copy link
Contributor

The stack traces are very useful, but as a customer facing CLI, it can be rather verbose and is useless unless they know the source code.

This introduces the concept of a debug mode for configuring when to print out the stack trace. Now the command will only print out stack traces when run with GRUNTWORK_DEBUG=1.

Note: I couldn't find a good way to unit test this, given that checkForErrorsAndExit kills the process. For now, here is the manual test demo:

Without env:

%~> go run main.go                                                                                                                                        [0]
ERRO[2018-11-28T11:31:10-08:00] --aws-region is required                      error="--aws-region is required"
exit status 1

With env:

%~> GRUNTWORK_DEBUG=1 go run main.go                                                                                                                      [1]
ERRO[2018-11-28T11:31:21-08:00] *errors.errorString --aws-region is required
/Users/yoriy/go/src/github.com/gruntwork-io/package-k8s/modules/k8s-binaries/cmd/eks-configure-kubectl/main.go:111 (0x114eb33)
        run: return gruntworkErrors.WithStackTrace(err)
/Users/yoriy/go/src/github.com/gruntwork-io/package-k8s/modules/k8s-binaries/vendor/github.com/urfave/cli/app.go:490 (0x11225c8)
        HandleAction: return a(context)
/Users/yoriy/go/src/github.com/gruntwork-io/package-k8s/modules/k8s-binaries/vendor/github.com/urfave/cli/app.go:264 (0x112083d)
        (*App).Run: err = HandleAction(a.Action, context)
/Users/yoriy/go/src/github.com/gruntwork-io/package-k8s/modules/k8s-binaries/vendor/github.com/gruntwork-io/gruntwork-cli/entrypoint/entrypoint.go:33 (0x11440f6)
        RunApp: err := app.Run(os.Args)
/Users/yoriy/go/src/github.com/gruntwork-io/package-k8s/modules/k8s-binaries/cmd/eks-configure-kubectl/main.go:174 (0x114ef3c)
        main: entrypoint.RunApp(app)
/usr/local/Cellar/go/1.11.2/libexec/src/runtime/proc.go:201 (0x102aba7)
        main: fn()
/usr/local/Cellar/go/1.11.2/libexec/src/runtime/asm_amd64.s:1333 (0x1055a51)
        goexit: BYTE    $0x90   // NOP  error="--aws-region is required"
exit status 1

@josh-padnick
Copy link

This is great! Should we just reduce the default logging to:

%~> go run main.go                                                                                                                                        
ERROR: --aws-region is required

@yorinasub17
Copy link
Contributor Author

+1 to @josh-padnick suggestion, so implemented it! I think this now closes #7

Copy link
Member

@brikis98 brikis98 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

func checkForErrorsAndExit(err error) {
exitCode := defaultSuccessExitCode
isDebugMode := os.Getenv(debugEnvironmentVarName) == "1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe if the var is not an empty string, we enable debug mode? I'll be tempted to set it to true or similar...

@yorinasub17
Copy link
Contributor Author

Ok merging. Will release this with the other 2.

@yorinasub17 yorinasub17 merged commit 90a8ba7 into master Nov 28, 2018
@yorinasub17 yorinasub17 deleted the yori-simple-error-messages branch November 28, 2018 22:51
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 this pull request may close these issues.

3 participants