{"record":{"id":"cda960b0daaf65b5","repo":"JuliusBrussee/caveman","slug":"mapped-source-path-q-for-required-target-q-was-n","errorCode":null,"errorMessage":"mapped source path %q for required target %q was not found","messagePattern":"mapped source path %q for required target %q was not found","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/importers/generic.go","lineNumber":135,"sourceCode":"\tvar env struct {\n\t\tData []map[string]any `json:\"data\"`\n\t}\n\tif err := json.Unmarshal(data, &env); err == nil && env.Data != nil {\n\t\treturn env.Data, nil\n\t}\n\treturn nil, fmt.Errorf(\"generic decode: expected a JSON array or {\\\"data\\\":[...]} of objects\")\n}\n\nfunc mapGeneric(rec map[string]any, opts Options) (Span, map[string]bool, error) {\n\tvar sp Span\n\tstartNs, endNs := int64(0), int64(0)\n\tresolved := make(map[string]bool, len(opts.FieldMap))\n\tfor target, path := range opts.FieldMap {\n\t\tkind := genericTargets[target]\n\t\tval, found := lookupPath(rec, path)\n\t\tif !found {\n\t\t\tif target == \"trace_id\" || target == \"span_id\" || target == \"timestamp\" {\n\t\t\t\treturn Span{}, nil, fmt.Errorf(\"mapped source path %q for required target %q was not found\", path, target)\n\t\t\t}\n\t\t\tcontinue\n\t\t}\n\t\tresolved[target] = true\n\t\tswitch kind {\n\t\tcase \"string\":\n\t\t\tassignString(&sp, target, asString(val))\n\t\tcase \"int\":\n\t\t\tassignInt(&sp, target, parseFlexInt(val))\n\t\tcase \"float\":\n\t\t\tsp.TotalCostUSD = roundUSD(parseFlexFloat(val))\n\t\tcase \"time\":\n\t\t\ts, ns := parseTimeFlexible(val)\n\t\t\tif target == \"timestamp\" {\n\t\t\t\tsp.Timestamp = s\n\t\t\t\tstartNs = ns\n\t\t\t} else {\n\t\t\t\tsp.EndTimestamp = s","sourceCodeStart":117,"sourceCodeEnd":153,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/27d5a3981a347890211bb1bf2439e5c821a63bc9/shared/platform/importers/generic.go#L117-L153","documentation":"During mapGeneric, the source path registered in FieldMap for a required target (trace_id, span_id, or timestamp) was resolved against the record with lookupPath and came back not-found. Required targets must resolve on every record, unlike optional targets which are silently skipped. The error names both the missing path and the target so you can see which mapping and which record field disagreed.","triggerScenarios":"FieldMap points to \"startTime\" but records use \"started_at\" (path mismatch); a dotted path like \"meta.traceId\" where the intermediate key differs or the nesting is absent on some records; one malformed record in the array missing the field entirely — mapping is per-record, so a single record without the path fails the whole import.","commonSituations":"Schema drift between export batches (vendor renamed a field); hand-written field map from documentation that is out of date; heterogeneous records where optional events lack the required timestamp field; case-sensitive path ('TraceId' vs 'traceId').","solutions":["Inspect the actual record JSON and correct the source path in FieldMap to the real key (watch case and nesting)","Verify lookupPath semantics: dotted paths traverse nested objects, so ensure each intermediate segment exists on every record","Pre-scan the data for records missing the required paths and fix or drop them before import","If the field is genuinely absent per-record, that record cannot be imported by this format — enrich it upstream"],"exampleFix":"// before\nopts.FieldMap = map[string]string{\n    \"trace_id\":  \"traceId\",\n    \"span_id\":   \"spanId\",\n    \"timestamp\": \"startTime\", // records actually use \"started_at\"\n}\n\n// after\nopts.FieldMap = map[string]string{\n    \"trace_id\":  \"traceId\",\n    \"span_id\":   \"spanId\",\n    \"timestamp\": \"started_at\",\n}","handlingStrategy":"validation","validationCode":"func verifyPaths(records []map[string]any, fm map[string]string) error {\n\tfor _, req := range []string{\"trace_id\", \"span_id\", \"timestamp\"} {\n\t\tok := false\n\t\tfor _, rec := range records {\n\t\t\tif _, found := lookupPath(rec, fm[req]); !found {\n\t\t\t\treturn fmt.Errorf(\"record missing path %q for %q\", fm[req], req)\n\t\t\t}\n\t\t\tok = true\n\t\t}\n\t\t_ = ok\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"if err != nil { var m *importers.MappingError; if errors.As(err, &m) { log.Printf(\"fix mapping for target %s\", m.Target) } }","preventionTips":["Dry-run one record through your own lookupPath before importing the full batch","Pin the source schema version in your export job and re-validate mappings when it changes","Keep field maps in version-controlled config reviewed on schema updates"],"tags":["go","import","generic","field-mapping"],"backgroundTag":null,"analyzedSha":"27d5a3981a347890211bb1bf2439e5c821a63bc9","analyzedAt":"2026-08-15T09:26:11.751Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}