{"record":{"id":"85e1f06dbdd95dd8","repo":"pulumi/pulumi","slug":"failed-to-convert-stack-output-t-to-object","errorCode":null,"errorMessage":"failed to convert stack output %T to object","messagePattern":"failed to convert stack output %T to object","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdk/go/pulumi/stack_reference.go","lineNumber":45,"sourceCode":"\n\t// Name is in the form \"Org/Program/Stack\"\n\tName StringOutput `pulumi:\"name\"`\n\t// Outputs resolves with exports from the named stack\n\tOutputs MapOutput `pulumi:\"outputs\"`\n\n\t// ctx is a reference to the context used to create the stack reference. It must be\n\t// valid and non-nil to call `GetOutput`.\n\tctx *Context\n}\n\n// GetOutput returns a stack output keyed by the given name as an AnyOutput\n// If the given name is not present in the StackReference, Output<nil> is returned.\nfunc (s *StackReference) GetOutput(name StringInput) AnyOutput {\n\treturn All(name, s.rawOutputs).\n\t\tApplyT(func(args []any) (any, error) {\n\t\t\tn, stack := args[0].(string), args[1].(resource.PropertyMap)\n\t\t\tif !stack[\"outputs\"].IsObject() {\n\t\t\t\treturn Any(nil), fmt.Errorf(\"failed to convert stack output %T to object\", stack)\n\t\t\t}\n\t\t\touts := stack[\"outputs\"].ObjectValue()\n\t\t\tv, ok := outs[resource.PropertyKey(n)]\n\t\t\tif !ok {\n\t\t\t\tif s.ctx.DryRun() {\n\t\t\t\t\t// It is a dry run, so it is safe to return an unknown output.\n\t\t\t\t\treturn UnsafeUnknownOutput([]Resource{s}), nil\n\t\t\t\t}\n\n\t\t\t\t// We don't return an error to remain consistent with other SDKs regarding missing keys.\n\t\t\t\treturn nil, nil\n\t\t\t}\n\n\t\t\tret, secret, _ := unmarshalPropertyValue(s.ctx, v)\n\n\t\t\tif secret {\n\t\t\t\tret = ToSecret(ret)\n\t\t\t}","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/pulumi/pulumi/blob/793f7b2e160db4321fb7fb6b0607461e01cb251e/sdk/go/pulumi/stack_reference.go#L27-L63","documentation":"StackReference.GetOutput fetches the referenced stack's outputs and expects the 'outputs' value to be an object. If it is not an object (e.g. the raw outputs state is unknown or a non-object shape), the Apply returns this error and the resulting AnyOutput becomes an error output.","triggerScenarios":"Calling StackReference.GetOutput(name) when the resolved rawOutputs property map's \"outputs\" entry is not a resource.PropertyValue holding an object — typically when outputs are unavailable/unknown during preview or the referenced stack state is malformed.","commonSituations":"Previewing (dry run) before the referenced stack's outputs are known; referencing a stack that has never been deployed or has no outputs; corrupt stack state.","solutions":["Ensure the referenced stack exists and has been successfully deployed with outputs (pulumi stack output in that project).","Check the stack reference name format (org/project/stack) for typos.","Handle the error output downstream (ApplyT error) or guard with a known-value check before use.","Refresh the referenced stack (pulumi refresh) if its state is stale."],"exampleFix":"// before\nsr := pulumi.NewStackReference(ctx, \"org/proj/stk\", nil)\nout := sr.GetOutput(pulumi.String(\"missingKey\"))\n// after — verify the referenced stack and key first\n// $ pulumi stack output missingKey --stack org/proj/stk  (run in referenced project)\n// then in the program handle the Apply error:\nout.ApplyT(func(v interface{}) (interface{}, error) {\n    // handle unknown/missing gracefully\n    return v, nil\n})","handlingStrategy":"validation","validationCode":"// verify referenced stack and outputs before referencing\n// $ pulumi stack select org/proj/stk && pulumi stack output\n// in program: verify key presence via export\n// pulumi stack export --stack org/proj/stk | jq '..outputs'","typeGuard":null,"tryCatchPattern":"sr.GetOutput(pulumi.String(\"key\")).ApplyT(func(v interface{}) (interface{}, error) {\n    if v == nil {\n        return nil, fmt.Errorf(\"output key not found\")\n    }\n    return v, nil\n})","preventionTips":["Confirm the referenced stack is deployed and has outputs before referencing","Use correct stack reference format org/project/stack","Run pulumi stack export to inspect actual output shape","Expect unknown outputs during preview and handle nil in ApplyT"],"tags":["go-sdk","stack-reference","outputs"],"backgroundTag":"stack-reference-output-missing","analyzedSha":"793f7b2e160db4321fb7fb6b0607461e01cb251e","analyzedAt":"2026-08-31T09:36:43.099Z","schemaVersion":2},"datasetVersion":"2026-08-31T14:17:45.589Z"}