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

  1. Only ever assign defined schema.ValueType constants to Type.
  2. Never cast an arbitrary int to ValueType; validate membership first.
  3. 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

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


AI-assisted analysis of hashicorp/terraform@c9def3e214 (2026-08-07). Data as JSON: /api/errors/b58a7405eccbfd65. Report an issue: GitHub.