porter icon indicating copy to clipboard operation
porter copied to clipboard

Print error stack traces in debug mode

Open carolynvs opened this issue 4 years ago • 2 comments

When porter is run in debug mode, with the --debug flag or config setting, then when our main program exits with an error, we shouldn't rely on the default cobra error handling. We should print the error with the included stack trace provided by the github.com/pkg/errors package.

That way we can more quickly drill down to where the error happened without doing greps on the error message.

It's not immediately clear to me how to provide our own error printing with cobra. But if we make this change on the v1 branch, we can check if p.Debug is set and print it before exiting.

https://github.com/getporter/porter/blob/9f88c6f8bc7066da70b67819013fcfbb4e12a9a9/cmd/porter/main.go#L18-L26

This change should be made against the release/v1 branch.

See our Contributing Tutorial and New Contributor Guide for help getting started contributing to Porter.

carolynvs avatar Aug 26 '21 17:08 carolynvs

We should print the error with the included stack trace provided by the github.com/pkg/errors package.

Given #2009 do we want to work towards removing the dependency on github.com/pkg/errors entirely and use something else here? Should runtime/debug be used in its place to implement this?

kevinbarbour avatar Jun 21 '22 12:06 kevinbarbour

@kevinbarbour Yes, thanks for picking up on the out-of-date implementation recommendation. runtime/debug is what we'd want to use

carolynvs avatar Jun 21 '22 14:06 carolynvs