{"record":{"id":"d61821ddb5112f6c","repo":"apache/beam","slug":"panic-v-s-call","errorCode":null,"errorMessage":"panic: %v %s","messagePattern":"panic: (.+?) (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/core/util/reflectx/call.go","lineNumber":125,"sourceCode":"\nfunc (f *namedFunc) Name() string          { return f.name }\nfunc (f *namedFunc) Type() reflect.Type    { return f.inner.Type() }\nfunc (f *namedFunc) Call(args []any) []any { return f.inner.Call(args) }\n\n// Interface returns the original unwrapped function, which\n// runtime.RegisterFunction needs for pointer extraction.\nfunc (f *namedFunc) Interface() any {\n\tif rf, ok := f.inner.(*reflectFunc); ok {\n\t\treturn rf.fn.Interface()\n\t}\n\treturn nil\n}\n\n// CallNoPanic calls the given Func and catches any panic.\nfunc CallNoPanic(fn Func, args []any) (ret []any, err error) {\n\tdefer func() {\n\t\tif r := recover(); r != nil {\n\t\t\terr = errors.Errorf(\"panic: %v %s\", r, debug.Stack())\n\t\t}\n\t}()\n\treturn fn.Call(args), nil\n}\n\n// ValueOf performs a per-element reflect.ValueOf.\nfunc ValueOf(list []any) []reflect.Value {\n\tret := make([]reflect.Value, len(list))\n\tfor i := 0; i < len(list); i++ {\n\t\tret[i] = reflect.ValueOf(list[i])\n\t}\n\treturn ret\n}\n\n// Interface performs a per-element Interface call.\nfunc Interface(list []reflect.Value) []any {\n\tret := make([]any, len(list))\n\tfor i := 0; i < len(list); i++ {","sourceCodeStart":107,"sourceCodeEnd":143,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/core/util/reflectx/call.go#L107-L143","documentation":"CallNoPanic invokes a reflectx Func but converts any Go panic raised during the call into an error instead of crashing. The error message embeds the recovered panic value plus the full debug stack trace.","triggerScenarios":"Any fn.Call(args) that panics: nil map/slice access, nil pointer dereference, type assertion failure, index out of range inside user-registered DoFn/function code invoked via CallNoPanic.","commonSituations":"User DoFns with nil elements in a PCollection, mismatched function signatures registered into the pipeline, or map lookups on nil maps inside element-processing functions.","solutions":["Read the debug.Stack() portion of the error to find the panicking frame in your function","Add nil checks / bounds checks inside the user function that panicked","Fix the registered function's signature to match the expected Func (correct number/types of args)"],"exampleFix":"// before\nfunc myDoFn(s string) string { return s[:3] }\n// after\nfunc myDoFn(s string) string {\n    if len(s) < 3 { return s } // guard against slice-bounds panic\n    return s[:3]\n}","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"ret, err := reflectx.CallNoPanic(fn, args)\nif err != nil {\n    log.Printf(\"function panicked: %v\", err) // error already embeds debug.Stack()\n    return err\n}","preventionTips":["Nil-check element values inside DoFns before slicing/mapping them","Verify registered function signatures match the expected Func arity and types","Prefer returning errors over panicking inside user pipeline functions"],"tags":["panic","reflection","go"],"backgroundTag":"unexpected-panic-recovered","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}