hashicorp/nomad · error

prefix %q; unsupported type %v

Error message

prefix %q; unsupported type %v

What it means

flatmap.flatten only supports maps, structs, slices/arrays, and primitives; any other reflect.Kind (e.g. chan, func, complex) hits the default branch and panics. It's an input-contract violation: the value being flattened must be composed of flatten-able types.

Source

Thrown at helper/flatmap/flatmap.go:110

		if !e.IsValid() {
			output[prefix] = "nil"
			return
		}
		flatten(prefix, e, primitiveOnly, enteredStruct, output)
	case reflect.Array, reflect.Slice:
		if primitiveOnly {
			return
		}

		if v.Kind() == reflect.Slice && v.IsNil() {
			output[prefix] = "nil"
			return
		}
		for i := 0; i < v.Len(); i++ {
			flatten(fmt.Sprintf("%s[%d]", prefix, i), v.Index(i), primitiveOnly, enteredStruct, output)
		}
	default:
		panic(fmt.Sprintf("prefix %q; unsupported type %v", prefix, v.Kind()))
	}
}

// getSubPrefix takes the current prefix and the next subfield and returns an
// appropriate prefix.
func getSubPrefix(curPrefix, subField string) string {
	if curPrefix != "" {
		return fmt.Sprintf("%s.%s", curPrefix, subField)
	}
	return subField
}

// getSubKeyPrefix takes the current prefix and the next subfield and returns an
// appropriate prefix for a map field.
func getSubKeyPrefix(curPrefix, subField string) string {
	if curPrefix != "" {
		return fmt.Sprintf("%s[%s]", curPrefix, subField)
	}

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Remove or exclude func/chan/complex fields from the struct before flattening
  2. Convert unsupported fields to supported representations (string, numbers, maps, slices)
  3. Nil out function/channel fields before calling Flatten

Example fix

// before
type Cfg struct{ Fn func() }
flatmap.Flatten(Cfg{Fn: func(){}}) // panics
// after
type Cfg struct{ Fn func() }
c := Cfg{Fn: func(){}}
c.Fn = nil // strip unsupported field
flatmap.Flatten(c)
Defensive patterns

Strategy: validation

Validate before calling

func flattenSupported(v reflect.Value) bool {
    switch v.Kind() {
    case reflect.Chan, reflect.Func, reflect.Complex64, reflect.Complex128, reflect.UnsafePointer:
        return false
    }
    return true
}

Type guard

func flattenSafe(v interface{}) (m map[string]string, ok bool) {
    defer func() {
        if r := recover(); r != nil { ok = false; m = nil }
    }()
    m = flatmap.Flatten(v)
    return m, true
}

Try / catch

defer func() {
    if r := recover(); r != nil {
        err = fmt.Errorf("flatmap unsupported type: %v", r)
    }
}()

Prevention

When it happens

Trigger: Passing a value containing a func, channel, complex number, or unsafe pointer field to flatmap.Flatten / flatmap.Diff.

Common situations: Structs with embedded callback functions or channels passed into Nomad's diff/flatten utilities; job/task config values containing complex types that flatmap never accounted for; changes to upstream structs adding unsupported field types.

Related errors


AI-assisted analysis of hashicorp/nomad@482b49bf1a (2026-09-04). Data as JSON: /api/errors/a48c6e9047e84e95. Report an issue: GitHub.