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

runtime: control panic behaviour programmatically #21777

mappu opened this issue Sep 6, 2017 · 2 comments

runtime: control panic behaviour programmatically #21777

mappu opened this issue Sep 6, 2017 · 2 comments


Copy link

@mappu mappu commented Sep 6, 2017

What version of Go are you using (go version)?

go version go1.9 windows/amd64 (latest)

What operating system and processor architecture are you using (go env)?

set GOARCH=amd64
set GOHOSTARCH=amd64
set GOHOSTOS=windows

What did you do?

If my application panics unexpectedly, Go produces a stack trace output, which is very useful for me to debug the issue.

However, I have an application that ships to end users. The stack trace is a technical document, not an end-user call to action.

What did you expect to see?

I have worked around this issue by adding a recover call in almost all of my goroutine invocations, that calls a common function to capture the stack trace and format it in a non-technical way. e.g. "please send the following message to your support contact: base64(gzip(panic data))"

What did you see instead?

Today in #21376 i ran across a panic in a goroutine started by the standard library. The full stack trace was displayed against my intention.

I obviously have no way of inserting a recover call into such a goroutine (well, except for patching all of std).

I would like a better way of controlling the panic, for all goroutines, without needing to insert recover calls and with support for panicking goroutines the standard library.

I am aware of GOTRACEBACK=none but i really do want these stack traces, in all cases. I just need them to be handled in a custom way.

@mdempsky mdempsky changed the title Control panic behaviour programmatically runtime: control panic behaviour programmatically Sep 6, 2017

This comment has been minimized.

Copy link

@ianlancetaylor ianlancetaylor commented Sep 8, 2017

Note that in the general case we can not run user code on program error. You cite #21376, but as far as I can see the example there is not a panic, it's an exception. An exception can not in general be recovered, so it's not clear that it matters that it was run on a library goroutine. That is, even if we provided a way to recover a panic on any arbitrary goroutine, for an exception that recover would never be run anyhow. So fixing that will not fix your real problem.

I think the only general way you can do what you want is to use a small wrapper program that starts your real program and handles the stack trace.

I'll leave this open for now but I suspect we're going to close this without taking any action, since any fix we make will be only partial.


This comment has been minimized.

Copy link

@ALTree ALTree commented Jun 28, 2019

It appears there was no support for doing this, so I'm closing this issue.

@ALTree ALTree closed this Jun 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.