From 3ab6fe5b4725bf5e29dbd069a7ed9a076a9890b6 Mon Sep 17 00:00:00 2001 From: Noah Treuhaft Date: Fri, 28 Aug 2026 11:50:43 -0400 Subject: [PATCH] book/super-example: recover from panics in main.run An unrecovered panic breaks the current page's Super instance and all examples on the page along with it. --- book/super-example/main.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/book/super-example/main.go b/book/super-example/main.go index aa714cab9a..c8f6f94c6c 100644 --- a/book/super-example/main.go +++ b/book/super-example/main.go @@ -6,7 +6,9 @@ import ( "bytes" "context" "errors" + "fmt" "io" + "runtime/debug" "slices" "strings" "syscall/js" @@ -45,7 +47,12 @@ type chunk struct { var errInvalidInput = errors.New("only string or ReadableStream accept as input") func run(opts opts) wasm.Promise { - return wasm.NewPromise(func() (interface{}, error) { + return wasm.NewPromise(func() (v interface{}, err error) { + defer func() { + if r := recover(); r != nil { + err = fmt.Errorf("panic: %+v\n\n%s\n", r, debug.Stack()) + } + }() flowgraph, err := parser.ParseText(opts.Program) if err != nil { return "", err