{"record":{"id":"3924ae51cb84ca48","repo":"pulumi/pulumi","slug":"result-field-type-s-does-not-match-expected-type","errorCode":null,"errorMessage":"result field type %s does not match expected type %s","messagePattern":"result field type (.+?) does not match expected type (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/pulumi/context.go","lineNumber":1293,"sourceCode":"\t\t\tif v.IsNil() {\n\t\t\t\treturn zeroType, errors.New(\"input cannot be a nil pointer\")\n\t\t\t}\n\t\t\t// Get the element the pointer points to\n\t\t\tv = v.Elem()\n\t\t}\n\n\t\tif v.Kind() != reflect.Map {\n\t\t\treturn zeroType, errors.New(\"result must be a map, but was a \" + v.Kind().String())\n\t\t}\n\n\t\tasMap := v.Interface().(map[string]any)\n\t\tif len(asMap) != 1 {\n\t\t\treturn zeroType, errors.New(\"result must have exactly one element\")\n\t\t}\n\n\t\tresult := slices.Collect(maps.Values(asMap))[0]\n\t\tif resultType := reflect.TypeOf(result); resultType != output.ElementType() {\n\t\t\treturn zeroType, fmt.Errorf(\"result field type %s does not match expected type %s\", resultType, output.ElementType())\n\t\t}\n\n\t\treturn result, nil\n\t})\n\n\toutputState := internal.GetOutputState(intermediary.(AnyOutput))\n\tif outputState == nil {\n\t\treturn nil, errors.New(\"intermediary output state is nil\")\n\t}\n\n\tresValue := reflect.New(reflect.TypeOf(output)).Elem()\n\tinternal.SetOutputState(resValue, outputState)\n\tres := resValue.Interface().(Output)\n\n\treturn res, nil\n}\n\n// ReadResource reads an existing custom resource's state from the resource monitor. t is the fully qualified type","sourceCodeStart":1275,"sourceCodeEnd":1311,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi/context.go#L1275-L1311","documentation":"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.","triggerScenarios":"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.","commonSituations":"Copy-pasting a Single call from another function with a different return type; schema changes in a provider upgrade altering a property's type.","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."],"exampleFix":"// before\nout, err := ctx.CallPackageSingle(tok, args, pulumi.StringOutput{}, nil, \"\") // field is int\n// after\nout, err := ctx.CallPackageSingle(tok, args, pulumi.Float64Output{}, nil, \"\")","handlingStrategy":"type-guard","validationCode":"// confirm the return field type in the provider schema matches the Output element type you request\n// schema.functions[tok].returns.properties[<field>].type == \"string\" for pulumi.StringOutput","typeGuard":"func matchesElementType(result any, out pulumi.Output) bool {\n    return reflect.TypeOf(result) == out.ElementType()\n}","tryCatchPattern":"out, err := ctx.CallPackageSingle(tok, args, pulumi.StringOutput{}, nil, \"\")\nif err != nil && strings.Contains(err.Error(), \"does not match expected type\") {\n    return fmt.Errorf(\"wrong output type requested for %s; see wrapped error for actual type\", tok)\n}","preventionTips":["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"],"tags":["go","pulumi-sdk","type-mismatch","reflection"],"backgroundTag":"unexpected-return-shape","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}