{"record":{"id":"c482b2e634e63fde","repo":"JuliusBrussee/caveman","slug":"langfuse-decode-w","errorCode":null,"errorMessage":"langfuse decode: %w","messagePattern":"langfuse decode: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/importers/langfuse.go","lineNumber":63,"sourceCode":"\tobs, err := decodeLangfuse(data)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\trows := make([]Span, 0, len(obs))\n\tfor _, o := range obs {\n\t\trows = append(rows, mapLangfuse(o, opts))\n\t}\n\treturn rows, nil\n}\n\nfunc decodeLangfuse(data []byte) ([]langfuseObservation, error) {\n\tvar env langfuseEnvelope\n\tif err := json.Unmarshal(data, &env); err == nil && env.Observations != nil {\n\t\treturn env.Observations, nil\n\t}\n\tvar arr []langfuseObservation\n\tif err := json.Unmarshal(data, &arr); err != nil {\n\t\treturn nil, fmt.Errorf(\"langfuse decode: %w\", err)\n\t}\n\treturn arr, nil\n}\n\nfunc mapLangfuse(o langfuseObservation, opts Options) Span {\n\tstart, startNs := parseTimeFlexible(o.StartTime)\n\tend, endNs := parseTimeFlexible(o.EndTime)\n\n\tstatus := \"ok\"\n\tswitch o.Level {\n\tcase \"ERROR\":\n\t\tstatus = \"error\"\n\tcase \"WARNING\":\n\t\tstatus = \"unset\"\n\t}\n\n\tspanType := o.Type\n\tif spanType == \"\" {","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/importers/langfuse.go#L45-L81","documentation":"decodeLangfuse tries the {\"observations\":[...]} envelope first, then a bare array of langfuseObservation objects. This error wraps the json.Unmarshal failure when the payload is neither shape, so no Langfuse observations can be decoded. The wrapped error pinpoints the JSON problem.","triggerScenarios":"Calling Parse with FormatLangfuse on data that is not a JSON array nor an object with an `observations` array: malformed JSON, a different envelope key (e.g. `data`), or array elements whose field types do not match langfuseObservation (e.g. numeric id, object where a string timestamp is expected).","commonSituations":"Feeding Helicone export JSON to the Langfuse importer; Langfuse API error bodies passed through; truncated export downloads; Langfuse API version changing field types; double-encoded JSON strings.","solutions":["Confirm the payload is either a bare JSON array of observations or {\"observations\":[...]}","Read the wrapped %w error for the exact JSON decode failure (offset/field) and fix it","Verify you selected the langfuse format, not helicone/generic, for this payload","Check element field types against langfuseObservation and pre-convert mismatches"],"exampleFix":"// before (helicone-style envelope)\n{\"data\":[{\"id\":\"1\"}]}\n// after\n{\"observations\":[{\"id\":\"1\",\"start_time\":\"2024-01-01T00:00:00Z\"}]}","handlingStrategy":"validation","validationCode":"func isLangfusePayload(data []byte) bool {\n  var env struct{ Observations []json.RawMessage `json:\"observations\"` }\n  if err := json.Unmarshal(data, &env); err == nil && env.Observations != nil { return true }\n  var arr []json.RawMessage\n  return json.Unmarshal(data, &arr) == nil\n}","typeGuard":null,"tryCatchPattern":"rows, err := importers.Parse(data, opts)\nif err != nil {\n  if strings.Contains(err.Error(), \"langfuse decode:\") {\n    return fmt.Errorf(\"payload is not a langfuse array or {\\\"observations\\\":[...]}: %w\", err)\n  }\n  return err\n}","preventionTips":["Validate JSON syntax and envelope key before import","Use the langfuse format only for Langfuse observation exports","Check element field types against langfuseObservation before import","Guard against API error bodies and truncated downloads reaching the importer"],"tags":["json","langfuse","import"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}