pulumi/pulumi · error
result field type %s does not match expected type %s
Error message
result field type %s does not match expected type %s
What it means
After unwrapping the single field, CallPackageSingle verifies the field's Go type matches the ElementType of the requested output. A mismatch yields 'result field type <actual> does not match expected type <expected>', preventing an unsafe reflective assignment.
Source
Thrown at sdk/go/pulumi/context.go:1293
if v.IsNil() {
return zeroType, errors.New("input cannot be a nil pointer")
}
// Get the element the pointer points to
v = v.Elem()
}
if v.Kind() != reflect.Map {
return zeroType, errors.New("result must be a map, but was a " + v.Kind().String())
}
asMap := v.Interface().(map[string]any)
if len(asMap) != 1 {
return zeroType, errors.New("result must have exactly one element")
}
result := slices.Collect(maps.Values(asMap))[0]
if resultType := reflect.TypeOf(result); resultType != output.ElementType() {
return zeroType, fmt.Errorf("result field type %s does not match expected type %s", resultType, output.ElementType())
}
return result, nil
})
outputState := internal.GetOutputState(intermediary.(AnyOutput))
if outputState == nil {
return nil, errors.New("intermediary output state is nil")
}
resValue := reflect.New(reflect.TypeOf(output)).Elem()
internal.SetOutputState(resValue, outputState)
res := resValue.Interface().(Output)
return res, nil
}
// ReadResource reads an existing custom resource's state from the resource monitor. t is the fully qualified typeView on GitHub (pinned to 793f7b2e16)
Solutions
- Match the output type to the actual field type (e.g. use pulumi.Float64Output for a number field).
- Consult the provider schema for the function's return type and adjust the requested Output type.
- If the provider changed types, pin the previous provider version or update program code.
Example fix
// before
out, err := ctx.CallPackageSingle(tok, args, pulumi.StringOutput{}, nil, "") // field is int
// after
out, err := ctx.CallPackageSingle(tok, args, pulumi.Float64Output{}, nil, "") Defensive patterns
Strategy: type-guard
Validate before calling
// confirm the return field type in the provider schema matches the Output element type you request // schema.functions[tok].returns.properties[<field>].type == "string" for pulumi.StringOutput
Type guard
func matchesElementType(result any, out pulumi.Output) bool {
return reflect.TypeOf(result) == out.ElementType()
} Try / catch
out, err := ctx.CallPackageSingle(tok, args, pulumi.StringOutput{}, nil, "")
if err != nil && strings.Contains(err.Error(), "does not match expected type") {
return fmt.Errorf("wrong output type requested for %s; see wrapped error for actual type", tok)
} Prevention
- Derive the requested Output type from the provider schema, not from guesswork
- Search the error text for the actual type name and switch to it
- Add unit tests asserting the element type of each Single wrapper
When it happens
Trigger: Requesting e.g. pulumi.StringOutput for a provider function whose single return field is a number/bool, or vice versa; provider changed the field's type across versions.
Common situations: Copy-pasting a Single call from another function with a different return type; schema changes in a provider upgrade altering a property's type.
Related errors
- result must be a map, but was a
- applier's %s input parameter must be assignable from %v, got
- cannot convert an input of type %T to a value of type %v
- input cannot be a nil pointer
- result must have exactly one element
AI-assisted analysis of pulumi/pulumi@793f7b2e16 (2026-08-31).
Data as JSON: /api/errors/3924ae51cb84ca48.
Report an issue: GitHub.