{"record":{"id":"41b637a5bbbd940c","repo":"BoundaryML/baml","slug":"failed-to-get-name-w","errorCode":null,"errorMessage":"failed to get name: %w","messagePattern":"failed to get name: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"engine/language_client_go/pkg/rawobjects_collector.go","lineNumber":44,"sourceCode":"\nfunc (c *collector) Usage() (Usage, error) {\n\tresult, err := raw_objects.CallMethod(c, \"usage\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get usage: %w\", err)\n\t}\n\n\tusage, ok := result.(Usage)\n\tif !ok {\n\t\treturn nil, fmt.Errorf(\"unexpected type for usage: %T\", result)\n\t}\n\n\treturn usage, nil\n}\n\nfunc (c *collector) Name() (string, error) {\n\tresult, err := raw_objects.CallMethod(c, \"name\", nil)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to get name: %w\", err)\n\t}\n\n\tname, ok := result.(string)\n\tif !ok {\n\t\treturn \"\", fmt.Errorf(\"unexpected type for name: %T\", result)\n\t}\n\n\treturn name, nil\n}\n\nfunc (c *collector) Logs() ([]FunctionLog, error) {\n\tresult, err := raw_objects.CallMethod(c, \"logs\", nil)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get logs: %w\", err)\n\t}\n\n\tlogs, ok := result.([]raw_objects.RawPointer)\n\tif !ok {","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/engine/language_client_go/pkg/rawobjects_collector.go#L26-L62","documentation":"Collector.Name() calls the runtime's `name` method and wraps any CallMethod failure as \"failed to get name: %w\". The wrapper hides the real cause, which arrives as the wrapped error: an FFI-level failure, a runtime exception, or an invalid collector object. It means the collector's name could not be fetched from the runtime at all — distinct from the type-assertion error that fires when decoding succeeds but the shape is wrong.","triggerScenarios":"Calling collector.Name() on a collector whose runtime object is invalid or freed, when the runtime raises inside `name`, or when the FFI bridge itself errors before returning a result.","commonSituations":"Using an anonymous collector created without a name where the runtime still errors instead of returning empty; accessing a collector after runtime teardown; sharing a collector across process boundaries.","solutions":["Inspect the wrapped cause via errors.Unwrap(err) to find the real failure.","Only call Name() on collectors created with b.Collector(\"name\", ...); construct named collectors explicitly.","Recreate the collector if the runtime was restarted, and keep usage within a single process lifetime.","Add a retry with backoff to distinguish transient FFI failures from a persistently broken object."],"exampleFix":"// before\nname, err := collector.Name()\n// after\nname, err := collector.Name()\nif err != nil {\n    return \"\", fmt.Errorf(\"collector name unavailable: %w\", err) // check wrapped cause\n}","handlingStrategy":"try-catch","validationCode":"// Create named collectors explicitly:\n// col := b.Collector(\"my-collector\", ...); if col == nil { ... }","typeGuard":"func hasName(c baml.Collector) bool { return c != nil }","tryCatchPattern":"name, err := collector.Name()\nif err != nil {\n    if strings.Contains(err.Error(), \"failed to get name\") {\n        return \"\", fmt.Errorf(\"collector unusable (runtime object invalid?): %w\", err)\n    }\n    return \"\", err\n}","preventionTips":["Use named collectors (b.Collector(\"name\", ...)) when you plan to read the name back","Keep collector usage inside the runtime's process lifetime","Check errors.Unwrap(err) to diagnose the true cause","Avoid using collectors after runtime teardown"],"tags":["go","ffi","collector","runtime"],"backgroundTag":"api-request-failed","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}