{"record":{"id":"c4351aaabb20ed65","repo":"JuliusBrussee/caveman","slug":"cachebench-observation-line-d-w","errorCode":null,"errorMessage":"cachebench: observation line %d: %w","messagePattern":"cachebench: observation line (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cacheengine/cachebench/observed.go","lineNumber":122,"sourceCode":"\tscanner.Buffer(make([]byte, initial), limits.MaxLineBytes)\n\tseen := map[string]bool{}\n\tvar records []ObservationRecord\n\tfor line := 1; scanner.Scan(); line++ {\n\t\traw := bytes.TrimSpace(scanner.Bytes())\n\t\tif len(raw) == 0 {\n\t\t\tcontinue\n\t\t}\n\t\tif len(records) >= limits.MaxRecords {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observations exceed record limit %d\", limits.MaxRecords)\n\t\t}\n\t\tif !validUniqueJSONObject(raw) {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: duplicate or invalid JSON\", line)\n\t\t}\n\t\tdecoder := json.NewDecoder(bytes.NewReader(raw))\n\t\tdecoder.DisallowUnknownFields()\n\t\tvar record ObservationRecord\n\t\tif err := decoder.Decode(&record); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: %w\", line, err)\n\t\t}\n\t\tvar trailing any\n\t\tif err := decoder.Decode(&trailing); err != io.EOF {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: trailing JSON\", line)\n\t\t}\n\t\tif record.Schema != ObservationSchema {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: schema %q\", line, record.Schema)\n\t\t}\n\t\tif strings.TrimSpace(record.RequestID) == \"\" || seen[record.RequestID] {\n\t\t\treturn nil, fmt.Errorf(\"cachebench: observation line %d: empty or duplicate request_id\", line)\n\t\t}\n\t\tseen[record.RequestID] = true\n\t\trecord.Usage = append(json.RawMessage(nil), record.Usage...)\n\t\trecords = append(records, record)\n\t}\n\tif err := scanner.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"cachebench: read observations: %w\", err)\n\t}","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/cacheengine/cachebench/observed.go#L104-L140","documentation":"The line passed JSON validation but could not decode into ObservationRecord, and the decoder runs with DisallowUnknownFields — so unknown fields are errors, not silent drops. The '%w' clause carries the encoding/json error naming the offending field or type problem, prefixed with the line number.","triggerScenarios":"Decoding an observation line that includes a field absent from ObservationRecord (schema drift), or a field with the wrong JSON type (e.g. request_id as a number).","commonSituations":"Observations written by a newer/older tool version with extra fields; hand-added metadata keys in observation JSONL; type changes across schema versions.","solutions":["Read the wrapped json error — it names the unknown field or type mismatch.","Strip fields not in the current ObservationRecord schema from the file.","Regenerate observations with the same tool version that will evaluate them."],"exampleFix":"// before\n{\"schema\":\"...\",\"request_id\":\"r1\",\"extra_field\":true}\n// after\n{\"schema\":\"...\",\"request_id\":\"r1\"}","handlingStrategy":"validation","validationCode":"func decodeObservation(line []byte) (ObservationRecord, error) {\n\tdec := json.NewDecoder(bytes.NewReader(line))\n\tdec.DisallowUnknownFields()\n\tvar rec ObservationRecord\n\tif err := dec.Decode(&rec); err != nil {\n\t\treturn ObservationRecord{}, err\n\t}\n\treturn rec, nil\n}\n// run over sample lines to catch schema drift before a full load","typeGuard":null,"tryCatchPattern":"if err := loadObservations(path, limits); err != nil {\n\tvar se *json.UnmarshalTypeError\n\tif errors.As(err, &se) {\n\t\t// field type drift: regenerate observations with current schema\n\t}\n\tif strings.Contains(err.Error(), \"unknown field\") {\n\t\t// strip the named field or regenerate the file\n\t}\n}","preventionTips":["Keep the writer and reader on the same tool version.","Prune unknown fields when transporting observation files across versions.","Pin the ObservationSchema value and reject others early."],"tags":["go","json","schema-drift","observations"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}