JuliusBrussee/caveman · error

mapped source path for required target was not found

Error message

mapped source path %q for required target %q was not found

What it means

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.

Solutions

  1. Check the exact dotted path in Options.FieldMap against the real record structure (trace_id, span_id, timestamp are required in every record)
  2. Fix typos and match nesting levels exactly (e.g. "trace.id" not "traceId" or "trace_id")
  3. Pre-validate records with a lookup against the same dotted path before calling Parse
  4. Remove or split out records that genuinely lack the required fields

Example fix

// before
FieldMap: map[string]string{"trace_id": "traceId", "span_id": "id", "timestamp": "created_at"}
// after (path matches the actual record nesting)
FieldMap: map[string]string{"trace_id": "trace.id", "span_id": "id", "timestamp": "created_at"}
Defensive patterns

Strategy: validation

Validate before calling

func pathExists(rec map[string]any, path string) bool {
  var cur any = rec
  for _, p := range strings.Split(path, ".") {
    m, ok := cur.(map[string]any); if !ok { return false }
    v, ok := m[p]; if !ok { return false }
    cur = v
  }
  return true
}
// before Parse: for _, t := range []string{"trace_id","span_id","timestamp"} {
//   if !pathExists(rec, fieldMap[t]) { return fmt.Errorf("missing %s path %s", t, fieldMap[t]) } }

Try / catch

rows, err := importers.Parse(data, opts)
if err != nil {
  var pathErr = regexp.MustCompile(`mapped source path "([^"]+)" for required target`)
  if m := pathErr.FindStringSubmatch(err.Error()); m != nil {
    return fmt.Errorf("field map: check source path %q: %w", m[1], err)
  }
  return err
}

Prevention

When it happens

Trigger: 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.

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

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

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

	var env struct {
		Data []map[string]any `json:"data"`
	}
	if err := json.Unmarshal(data, &env); err == nil && env.Data != nil {
		return env.Data, nil
	}
	return nil, fmt.Errorf("generic decode: expected a JSON array or {\"data\":[...]} of objects")
}

func mapGeneric(rec map[string]any, opts Options) (Span, map[string]bool, error) {
	var sp Span
	startNs, endNs := int64(0), int64(0)
	resolved := make(map[string]bool, len(opts.FieldMap))
	for target, path := range opts.FieldMap {
		kind := genericTargets[target]
		val, found := lookupPath(rec, path)
		if !found {
			if target == "trace_id" || target == "span_id" || target == "timestamp" {
				return Span{}, nil, fmt.Errorf("mapped source path %q for required target %q was not found", path, target)
			}
			continue
		}
		resolved[target] = true
		switch kind {
		case "string":
			assignString(&sp, target, asString(val))
		case "int":
			assignInt(&sp, target, parseFlexInt(val))
		case "float":
			sp.TotalCostUSD = roundUSD(parseFlexFloat(val))
		case "time":
			s, ns := parseTimeFlexible(val)
			if target == "timestamp" {
				sp.Timestamp = s
				startNs = ns
			} else {
				sp.EndTimestamp = s

View on GitHub (pinned to 3ee70a1026)