{"record":{"id":"f42a3256173cd491","repo":"go-delve/delve","slug":"panic-executing-starlark-script-v","errorCode":null,"errorMessage":"panic executing starlark script: %v","messagePattern":"panic executing starlark script: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/terminal/starbind/starlark.go","lineNumber":230,"sourceCode":"}\n\nfunc (env *Env) printFunc() func(_ *starlark.Thread, msg string) {\n\treturn func(_ *starlark.Thread, msg string) { fmt.Fprintln(env.out, msg) }\n}\n\n// Execute executes a script. Path is the name of the file to execute and\n// source is the source code to execute.\n// Source can be either a []byte, a string or a io.Reader. If source is nil\n// Execute will execute the file specified by 'path'.\n// After the file is executed if a function named mainFnName exists it will be called, passing args to it.\nfunc (env *Env) Execute(path string, source any, mainFnName string, args []any) (_ starlark.Value, _err error) {\n\tdefer func() {\n\t\terr := recover()\n\t\tif err == nil {\n\t\t\treturn\n\t\t}\n\t\tlogflags.Bug.Inc()\n\t\t_err = fmt.Errorf(\"panic executing starlark script: %v\", err)\n\t\tfmt.Fprintf(env.out, \"panic executing starlark script: %v\\n\", err)\n\t\tfor i := 0; ; i++ {\n\t\t\tpc, file, line, ok := runtime.Caller(i)\n\t\t\tif !ok {\n\t\t\t\tbreak\n\t\t\t}\n\t\t\tfname := \"<unknown>\"\n\t\t\tfn := runtime.FuncForPC(pc)\n\t\t\tif fn != nil {\n\t\t\t\tfname = fn.Name()\n\t\t\t}\n\t\t\tfmt.Fprintf(env.out, \"%s\\n\\tin %s:%d\\n\", fname, file, line)\n\t\t}\n\t}()\n\n\tthread := env.newThread()\n\tglobals, err := execFileOptions(nil, thread, path, source, env.env)\n\tif err != nil {","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/go-delve/delve/blob/a23773e6c31361e43246bc43a424ee009679b174/pkg/terminal/starbind/starlark.go#L212-L248","documentation":"This is a catch-all panic recovery wrapper around starlark script execution in delve's starbind package. When a user script (or a bug in the binding layer) panics during script evaluation, the deferred recover converts the panic into an error and prints it with a full goroutine stack trace to the debugger console. It also increments the internal bug counter because a panic inside starlark bindings usually indicates a defect rather than a normal scripting mistake.","triggerScenarios":"Any panic during starlark script execution via delve's scripting support, e.g. nil pointer dereference in a bound Go function, index-out-of-range inside a builtin the script calls, or calling a bound API with values that violate invariants.","commonSituations":"Users running complex .star scripts against the debugger (service call scripts, automation) hit this when a builtin panics; it also appears after delve version upgrades where a script relies on a binding whose signature changed.","solutions":["Read the printed stack trace to find the Go frame that panicked (usually a starbind builtin or starlark runtime frame).","Fix the starlark script if it passes invalid arguments to a builtin.","If the panic is inside delve's bindings, reproduce with the script and file a bug with the script and stack trace.","Update delve; known starlark binding panics are fixed between versions."],"exampleFix":"// before (script causing panic)\nbp = debug.GetBreakpoint()\nprint(bp.Args)  # nil deref in a binding\n// after\nbp = debug.GetBreakpoint()\nif bp != None:\n    print(bp)","handlingStrategy":"try-catch","validationCode":"// starlark: validate values before calling risky builtins\nif bp == None:\n    fail('breakpoint not found')\nprint(bp.Id)","typeGuard":null,"tryCatchPattern":"// In Go host code wrapping Execute (delve already recovers):\nerr := env.Execute(script, args)\nif err != nil && strings.HasPrefix(err.Error(), \"panic executing starlark script\") {\n    log.Printf(\"script panicked: %v\", err) // stack already printed to env.out\n}","preventionTips":["Nil-check results from bound builtins before use in scripts","Test scripts against the target delve version in CI","Keep scripts small so stack traces are easy to read","Report panics with the full printed stack to delve maintainers"],"tags":["go","starlark","panic-recovery","scripting"],"backgroundTag":"panic-recovered-in-script-engine","analyzedSha":"a23773e6c31361e43246bc43a424ee009679b174","analyzedAt":"2026-08-31T15:12:45.221Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}