Skip to content

Commit

Permalink
runtime/debug: add SetCrashOutput(...CrashOptions) parameter
Browse files Browse the repository at this point in the history
This is a placeholder for future options (e.g. JSON).

The parameter is temporarily variadic to avoid breaking
x/telemetry (see CL 585378), but I plan to remove
the "..." later this week.

Updates golang#67182

Change-Id: I3f6f39455d852f92902f8e3f007d3093cbe555db
Reviewed-on: https://go-review.googlesource.com/c/go/+/585557
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
  • Loading branch information
adonovan committed May 15, 2024
1 parent 3d80761 commit 3f7a030
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
3 changes: 2 additions & 1 deletion api/next/42888.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pkg runtime/debug, func SetCrashOutput(*os.File) error #42888
pkg runtime/debug, type CrashOptions struct #67182
pkg runtime/debug, func SetCrashOutput(*os.File, ...CrashOptions) error #42888
1 change: 1 addition & 0 deletions doc/next/6-stdlib/99-minor/runtime/debug/67182.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!-- pacify TestCheckAPIFragments -->
15 changes: 14 additions & 1 deletion src/runtime/debug/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ func Stack() []byte {
}
}

// CrashOptions provides options that control the formatting of the
// fatal crash message.
type CrashOptions struct {
/* for future expansion */
}

// SetCrashOutput configures a single additional file where unhandled
// panics and other fatal errors are printed, in addition to standard error.
// There is only one additional file: calling SetCrashOutput again overrides
Expand All @@ -40,7 +46,14 @@ func Stack() []byte {
// To disable this additional crash output, call SetCrashOutput(nil).
// If called concurrently with a crash, some in-progress output may be written
// to the old file even after an overriding SetCrashOutput returns.
func SetCrashOutput(f *os.File) error {
//
// TODO(adonovan): the variadic ... is a short-term measure to avoid
// breaking the call in x/telemetry; it will be removed before the
// go1.23 freeze.
func SetCrashOutput(f *os.File, opts ...CrashOptions) error {
if len(opts) > 1 {
panic("supply at most 1 CrashOptions")
}
fd := ^uintptr(0)
if f != nil {
// The runtime will write to this file descriptor from
Expand Down

0 comments on commit 3f7a030

Please sign in to comment.