hashicorp/terraform · critical
unknown type %s
Error message
unknown type %s
What it means
Panics in ValueType.Zero (schema.go:1777). The switch returns the Go zero value for every defined ValueType constant; the default panics. This means the ValueType passed in is an integer that does not correspond to any defined constant (TypeInvalid is handled and returns nil, so this is strictly an out-of-range value).
Source
Thrown at internal/legacy/helper/schema/schema.go:1777
return nil
case TypeBool:
return false
case TypeInt:
return 0
case TypeFloat:
return 0.0
case TypeString:
return ""
case TypeList:
return []interface{}{}
case TypeMap:
return map[string]interface{}{}
case TypeSet:
return new(Set)
case typeObject:
return map[string]interface{}{}
default:
panic(fmt.Sprintf("unknown type %s", t))
}
}
View on GitHub (pinned to c9def3e214)
Solutions
- Only ever assign defined schema.ValueType constants to Type.
- Never cast an arbitrary int to ValueType; validate membership first.
- If schema descriptors come from external data, validate the type id against the known constants before use.
Example fix
// before
vt := ValueType(someInt) // someInt may be out of range
v := vt.Zero()
// after
if vt < TypeInvalid || vt > typeObject { panic("bad type id") }
v := vt.Zero() Defensive patterns
Strategy: type-guard
Validate before calling
func valueTypeInRange(t schema.ValueType) bool {
return t >= schema.TypeInvalid && t <= schema.TypeSet
} Type guard
func knownValueType(t schema.ValueType) bool {
switch t {
case schema.TypeInvalid, schema.TypeBool, schema.TypeInt, schema.TypeFloat,
schema.TypeString, schema.TypeList, schema.TypeMap, schema.TypeSet:
return true
}
return false
} Prevention
- Never cast arbitrary ints to ValueType.
- Validate external type ids against known constants before use.
- Avoid reflection-built schemas with raw type integers.
When it happens
Trigger: A Schema.Type set to a numeric value outside the defined ValueType enum range — typically from unsafe int casting, reflection, fuzzing, or corrupt schema/state data — then Zero() is invoked.
Common situations: Interop/reflection code that casts arbitrary ints to ValueType, fuzz tests, or hand-assembled schema descriptors.
Related errors
- Unknown type: %#v
- missing field in set: %s.%s
- set item just set doesn't exist
- invalid set element type
- Unknown validation type: %#v
AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07).
Data as JSON: /api/errors/b58a7405eccbfd65.
Report an issue: GitHub.