JuliusBrussee/caveman · error

generic import requires a non-empty field map

Error message

generic import requires a non-empty field map

What it means

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.

Solutions

  1. Populate opts.FieldMap with at least trace_id, span_id, and timestamp mappings.
  2. If importing caveman's native JSONL, use the dedicated caveman-jsonl importer instead of the generic one.
  3. Check that config loading (YAML/env/flags) actually reaches the FieldMap field.
  4. Verify the import command passes the map option (e.g. --map target=path).

Example fix

// before
opts := GenericOptions{} // FieldMap empty
// after
opts := GenericOptions{FieldMap: map[string]string{
  "trace_id": "traceId", "span_id": "spanId", "timestamp": "ts",
}}
Defensive patterns

Strategy: validation

Validate before calling

if len(opts.FieldMap) == 0 {
	return errors.New("generic import: FieldMap must define trace_id, span_id and timestamp")
}

Try / catch

rows, err := importers.ParseGeneric(data, opts)
if err != nil {
	if strings.Contains(err.Error(), "non-empty field map") {
		return errors.New("no --map options given; supply target=path mappings")
	}
	return err
}

Prevention

When it happens

Trigger: Calling Parse() with opts.FieldMap == nil or an empty map for a generic import.

Common situations: 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.

Understand the failure class

Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/50ac273eadb665c7. Report an issue: GitHub.

Appendix: source

Thrown at shared/platform/importers/generic.go:92

		if err != nil {
			return nil, fmt.Errorf("generic record %d: %w", i+1, err)
		}
		for target := range resolved {
			resolvedTargets[target] = true
		}
		rows = append(rows, sp)
	}
	for target, path := range opts.FieldMap {
		if !resolvedTargets[target] {
			return nil, fmt.Errorf("mapped source path %q for target %q was not found in any record", path, target)
		}
	}
	return rows, nil
}

func validateGenericFieldMap(fieldMap map[string]string) error {
	if len(fieldMap) == 0 {
		return fmt.Errorf("generic import requires a non-empty field map")
	}
	for target, path := range fieldMap {
		if _, ok := genericTargets[target]; !ok {
			return fmt.Errorf("unknown target column %q (not a caveman.spans column)", target)
		}
		if strings.TrimSpace(path) == "" {
			return fmt.Errorf("generic target %q requires a non-empty source path", target)
		}
	}
	for _, target := range []string{"trace_id", "span_id", "timestamp"} {
		if _, ok := fieldMap[target]; !ok {
			return fmt.Errorf("generic import requires a %q mapping", target)
		}
	}
	return nil
}

func decodeGenericRecords(data []byte) ([]map[string]any, error) {

View on GitHub (pinned to 3ee70a1026)