aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Donovan <adonovan@google.com>2024-05-15 14:55:19 -0400
committerAlan Donovan <adonovan@google.com>2024-05-15 21:04:14 +0000
commit3f7a030e02c31aaf28e8e107270d6b33920c1cae (patch)
tree98c6f48e4e547d0e28f3fc04fbe69ce7294154e7
parent3d80761531a6eb02934bc6b7236d77723f0b54fe (diff)
downloadgo-3f7a030e02c31aaf28e8e107270d6b33920c1cae.tar.gz
go-3f7a030e02c31aaf28e8e107270d6b33920c1cae.zip
runtime/debug: add SetCrashOutput(...CrashOptions) parameter
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 #67182 Change-Id: I3f6f39455d852f92902f8e3f007d3093cbe555db Reviewed-on: https://go-review.googlesource.com/c/go/+/585557 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Austin Clements <austin@google.com>
-rw-r--r--api/next/42888.txt3
-rw-r--r--doc/next/6-stdlib/99-minor/runtime/debug/67182.md1
-rw-r--r--src/runtime/debug/stack.go15
3 files changed, 17 insertions, 2 deletions
diff --git a/api/next/42888.txt b/api/next/42888.txt
index f9b8e1e475..dcba97b9fa 100644
--- a/api/next/42888.txt
+++ b/api/next/42888.txt
@@ -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
diff --git a/doc/next/6-stdlib/99-minor/runtime/debug/67182.md b/doc/next/6-stdlib/99-minor/runtime/debug/67182.md
new file mode 100644
index 0000000000..d83864a3db
--- /dev/null
+++ b/doc/next/6-stdlib/99-minor/runtime/debug/67182.md
@@ -0,0 +1 @@
+<!-- pacify TestCheckAPIFragments --> \ No newline at end of file
diff --git a/src/runtime/debug/stack.go b/src/runtime/debug/stack.go
index 8dfea52d34..dc7dc5d569 100644
--- a/src/runtime/debug/stack.go
+++ b/src/runtime/debug/stack.go
@@ -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
@@ -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