hashicorp/nomad · error

cannot serialize %s

Error message

cannot serialize %s

What it means

ctyValueToInterface handles primitive, list/tuple, map/object, set, and capsule types. Any other cty type (e.g. a type without a defined Go mapping) reaches the default branch and fails with 'cannot serialize <FriendlyName>'.

Source

Thrown at helper/pluginutils/hclutils/util.go:176

	case t.IsObjectType():
		result := map[string]interface{}{}

		for k := range t.AttributeTypes() {
			av := val.GetAttr(k)
			avv, err := ctyValueToInterface(av)
			if err != nil {
				return nil, err
			}

			result[k] = avv
		}
		return result, nil

	case t.IsCapsuleType():
		return val.EncapsulatedValue(), nil

	default:
		return nil, fmt.Errorf("cannot serialize %s", t.FriendlyName())
	}
}

func smallestNumber(b *big.Float) interface{} {
	if v, acc := b.Int64(); acc == big.Exact {
		if int64(int(v)) == v {
			return int(v)
		}
		return v
	}

	v, _ := b.Float64()
	return v
}

// GetStdlibFuncs returns the set of stdlib functions.
func GetStdlibFuncs() map[string]function.Function {
	return map[string]function.Function{

View on GitHub (pinned to 482b49bf1a)

Solutions

  1. Avoid putting the unsupported type in the converted payload; convert only supported cty types.
  2. If it is a capsule type you control, extract data via EncapsulatedValue before conversion.
  3. Extend ctyValueToInterface with a case for the named type (its FriendlyName is in the message).

Example fix

// before
return nil, fmt.Errorf("cannot serialize %s", t.FriendlyName())
// after
case t.IsCapsuleType():
    return val.EncapsulatedValue(), nil
// (add handling instead of erroring)
Defensive patterns

Strategy: validation

Validate before calling

t := val.Type()
supported := t.IsPrimitiveType() || t.IsListType() || t.IsMapType() ||
    t.IsSetType() || t.IsTupleType() || t.IsObjectType() || t.IsCapsuleType()
if !supported {
    return fmt.Errorf("cannot serialize %s", t.FriendlyName())
}

Try / catch

m, err := CtyValueToMapInterface(val)
if err != nil && strings.HasPrefix(err.Error(), "cannot serialize") {
    return fmt.Errorf("unsupported config value type: %w", err)
}

Prevention

When it happens

Trigger: Converting a cty.Value whose type falls outside the supported set — typically an exotic capsule-ish or dynamically typed value reaching the default branch after the switch.

Common situations: Custom providers/plugins embedding capsule types into config values; upgrades where new cty types appear but the converter was not extended.

Related errors


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