Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[codegen/go] Update Go SDK function output to check for errors #9274

Merged
merged 3 commits into from Mar 25, 2022

Conversation

guineveresaenger
Copy link
Contributor

@guineveresaenger guineveresaenger commented Mar 23, 2022

Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if err != nil {
				return nil, err
			}
			if r == nil {
				return nil, fmt.Errorf("expected either result or error to be nil, not both")
			}
			return *r, err
		}).(GetPolicyDocumentResultOutput)
}

Description

Fixes # (issue)

Checklist

  • I have added tests that prove my fix is effective or that my feature works
  • Yes, there are changes in this PR that warrants bumping the Pulumi Service API version

@github-actions
Copy link

Diff for pulumi-random with merge commit 78f5af7

@github-actions
Copy link

Diff for pulumi-azuread with merge commit 78f5af7

@github-actions
Copy link

Diff for pulumi-kubernetes with merge commit 78f5af7

@github-actions
Copy link

Diff for pulumi-gcp with merge commit 78f5af7

@github-actions
Copy link

Diff for pulumi-azure with merge commit 78f5af7

@github-actions
Copy link

Diff for pulumi-aws with merge commit 78f5af7

@t0yv0
Copy link
Member

t0yv0 commented Mar 24, 2022

Minor corrections here: #9284
Thanks so much. This is the right place for the fix.

Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if err != nil {
				return nil, err
			}
			if r == nil {
				return nil, fmt.Errorf("expected either result or error to be nil, not both")
			}
			return *r, err
		}).(GetPolicyDocumentResultOutput)
}
```
@github-actions
Copy link

Diff for pulumi-azuread with merge commit 72e5489

@github-actions
Copy link

Diff for pulumi-random with merge commit 72e5489

@github-actions
Copy link

Diff for pulumi-kubernetes with merge commit 72e5489

@github-actions
Copy link

Diff for pulumi-gcp with merge commit 72e5489

@github-actions
Copy link

Diff for pulumi-azure with merge commit 72e5489

@github-actions
Copy link

Diff for pulumi-aws with merge commit 72e5489

t0yv0 and others added 2 commits March 24, 2022 11:52
* [codegen/go] Update Go SDK function output to check for errors

Fixes pulumi/pulumi-aws#1872.

This should result in the following sample output in the Go SDK:

```
func GetPolicyDocumentOutput(ctx *pulumi.Context, args GetPolicyDocumentOutputArgs, opts ...pulumi.InvokeOption) GetPolicyDocumentResultOutput {
	return pulumi.ToOutputWithContext(context.Background(), args).
		ApplyT(func(v interface{}) (GetPolicyDocumentResult, error) {
			args := v.(GetPolicyDocumentArgs)
			r, err := GetPolicyDocument(ctx, &args, opts...)
			if r != nil {
				s = *r
			}
			return s, err
		}).(GetPolicyDocumentResultOutput)
}
```

* Alternate fix to safeguard dereferencing nil

* Accept codegen changes in the test suite

Co-authored-by: Guinevere Saenger <guinevere@pulumi.com>
@github-actions
Copy link

Diff for pulumi-azuread with merge commit 499e3d7

@github-actions
Copy link

Diff for pulumi-random with merge commit 499e3d7

@github-actions
Copy link

Diff for pulumi-kubernetes with merge commit 499e3d7

@github-actions
Copy link

Diff for pulumi-gcp with merge commit 499e3d7

@github-actions
Copy link

Diff for pulumi-azure with merge commit 499e3d7

@github-actions
Copy link

Diff for pulumi-aws with merge commit 499e3d7

@github-actions
Copy link

Diff for pulumi-azure-native with merge commit 499e3d7

@guineveresaenger guineveresaenger merged commit de0dcbf into master Mar 25, 2022
@pulumi-bot pulumi-bot deleted the guin/fix-error-panic branch March 25, 2022 03:11
@ghostsquad
Copy link
Contributor

I'm running pulumi cli 3.37.2, and it appears this is still an issue. Do you know what's going on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GetPolicyDocumentOutput panics instead of returning error
3 participants