{"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/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/importers/generic.go#L117-L153","documentation":"In the generic importer, the FieldMap targets `trace_id`, `span_id`, and `timestamp` are required. When the dotted source path configured for one of these does not resolve in a record (the key is absent, or an intermediate path segment is not an object), this error is returned for that record. It prevents spans with no identity or time from being silently created.","triggerScenarios":"Calling Parse with FormatGeneric and an Options.FieldMap whose trace_id/span_id/timestamp source path (e.g. \"trace.id\") does not exist in at least one record, or whose intermediate key is a scalar/array rather than an object so lookupPath cannot descend.","commonSituations":"Typo in the dotted path (\"traceId\" vs \"trace.id\"); records from a provider where the field is nested differently or renamed; per-record nulls that collapse a nested object; mixing records from two sources with different schemas in one file.","solutions":["Check the exact dotted path in Options.FieldMap against the real record structure (trace_id, span_id, timestamp are required in every record)","Fix typos and match nesting levels exactly (e.g. \"trace.id\" not \"traceId\" or \"trace_id\")","Pre-validate records with a lookup against the same dotted path before calling Parse","Remove or split out records that genuinely lack the required fields"],"exampleFix":"// before\nFieldMap: map[string]string{\"trace_id\": \"traceId\", \"span_id\": \"id\", \"timestamp\": \"created_at\"}\n// after (path matches the actual record nesting)\nFieldMap: map[string]string{\"trace_id\": \"trace.id\", \"span_id\": \"id\", \"timestamp\": \"created_at\"}","handlingStrategy":"validation","validationCode":"func pathExists(rec map[string]any, path string) bool {\n  var cur any = rec\n  for _, p := range strings.Split(path, \".\") {\n    m, ok := cur.(map[string]any); if !ok { return false }\n    v, ok := m[p]; if !ok { return false }\n    cur = v\n  }\n  return true\n}\n// before Parse: for _, t := range []string{\"trace_id\",\"span_id\",\"timestamp\"} {\n//   if !pathExists(rec, fieldMap[t]) { return fmt.Errorf(\"missing %s path %s\", t, fieldMap[t]) } }","typeGuard":null,"tryCatchPattern":"rows, err := importers.Parse(data, opts)\nif err != nil {\n  var pathErr = regexp.MustCompile(`mapped source path \"([^\"]+)\" for required target`)\n  if m := pathErr.FindStringSubmatch(err.Error()); m != nil {\n    return fmt.Errorf(\"field map: check source path %q: %w\", m[1], err)\n  }\n  return err\n}","preventionTips":["Verify dotted paths against real record samples before configuring FieldMap","Keep required mappings (trace_id, span_id, timestamp) pointing at top-level reliable keys","Test FieldMap on one representative record before full import","Avoid paths through fields that can be null in some records"],"tags":["import","field-mapping","validation"],"backgroundTag":"missing-required-argument","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"}