{"record":{"id":"50ac273eadb665c7","repo":"JuliusBrussee/caveman","slug":"generic-import-requires-a-non-empty-field-map","errorCode":null,"errorMessage":"generic import requires a non-empty field map","messagePattern":"generic import requires a non-empty field map","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"shared/platform/importers/generic.go","lineNumber":92,"sourceCode":"\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"generic record %d: %w\", i+1, err)\n\t\t}\n\t\tfor target := range resolved {\n\t\t\tresolvedTargets[target] = true\n\t\t}\n\t\trows = append(rows, sp)\n\t}\n\tfor target, path := range opts.FieldMap {\n\t\tif !resolvedTargets[target] {\n\t\t\treturn nil, fmt.Errorf(\"mapped source path %q for target %q was not found in any record\", path, target)\n\t\t}\n\t}\n\treturn rows, nil\n}\n\nfunc validateGenericFieldMap(fieldMap map[string]string) error {\n\tif len(fieldMap) == 0 {\n\t\treturn fmt.Errorf(\"generic import requires a non-empty field map\")\n\t}\n\tfor target, path := range fieldMap {\n\t\tif _, ok := genericTargets[target]; !ok {\n\t\t\treturn fmt.Errorf(\"unknown target column %q (not a caveman.spans column)\", target)\n\t\t}\n\t\tif strings.TrimSpace(path) == \"\" {\n\t\t\treturn fmt.Errorf(\"generic target %q requires a non-empty source path\", target)\n\t\t}\n\t}\n\tfor _, target := range []string{\"trace_id\", \"span_id\", \"timestamp\"} {\n\t\tif _, ok := fieldMap[target]; !ok {\n\t\t\treturn fmt.Errorf(\"generic import requires a %q mapping\", target)\n\t\t}\n\t}\n\treturn nil\n}\n\nfunc decodeGenericRecords(data []byte) ([]map[string]any, error) {","sourceCodeStart":74,"sourceCodeEnd":110,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/shared/platform/importers/generic.go#L74-L110","documentation":"validateGenericFieldMap rejects an empty field map: a generic import cannot proceed without at least one source-path-to-target-column mapping. parseGeneric calls this validation before processing records.","triggerScenarios":"Calling Parse() with opts.FieldMap == nil or an empty map for a generic import.","commonSituations":"Forgetting to populate FieldMap in config/CLI options; a loader producing an empty map from a blank config file; an import command run without any --map flags.","solutions":["Populate opts.FieldMap with at least trace_id, span_id, and timestamp mappings.","If importing caveman's native JSONL, use the dedicated caveman-jsonl importer instead of the generic one.","Check that config loading (YAML/env/flags) actually reaches the FieldMap field.","Verify the import command passes the map option (e.g. --map target=path)."],"exampleFix":"// before\nopts := GenericOptions{} // FieldMap empty\n// after\nopts := GenericOptions{FieldMap: map[string]string{\n  \"trace_id\": \"traceId\", \"span_id\": \"spanId\", \"timestamp\": \"ts\",\n}}","handlingStrategy":"validation","validationCode":"if len(opts.FieldMap) == 0 {\n\treturn errors.New(\"generic import: FieldMap must define trace_id, span_id and timestamp\")\n}","typeGuard":null,"tryCatchPattern":"rows, err := importers.ParseGeneric(data, opts)\nif err != nil {\n\tif strings.Contains(err.Error(), \"non-empty field map\") {\n\t\treturn errors.New(\"no --map options given; supply target=path mappings\")\n\t}\n\treturn err\n}","preventionTips":["Always populate the three required mappings when using the generic importer.","Assert the FieldMap is non-empty right after config load.","Provide a config template that includes the required keys.","Fail fast in CLI flag parsing if zero --map flags were given."],"tags":["generic-import","field-map","config","importer"],"backgroundTag":"empty-required-field","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"}