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
[cli/import] - Handle panic during import codegen #7265
Conversation
8b6e918
to
cb8bb3d
Compare
cb8bb3d
to
31c78b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
handle a panic that is caused by a failure during go codegen
Is there a reason we can't have codegen return a real error instead of panicng? It wasn't entirely clear here what call in the code here is panicing, and why that is expected such that we need to add a panic handler at this layer?
Assuming there is a good need to still be panicing in the codegen, this change certainly looks like it helps improve the UX for pulumi import
.
Unfortunately, import is impossible to write tests for since it is dependent on a resource existing in a provider. The original PR to add the import command included no tests.
Technically I believe we could import a resource like random.RandomString
which doesn't have any backing cloud provider state (or have a "dummy" resource provider that we test against). But I agree we can tackle test coverage here independently of this PR.
So, this is the line that panics: pulumi/pkg/codegen/go/gen_program.go Line 92 in 3e3e4f2
You're right though, it should just return an error. The reason that I didn't fix it at that layer is because docgen has existing code to work around this, and I wanted to avoid working in multiple layers and potentially alter the behavior of existing tooling to get to resolution here. The reason we're getting to this panic, in this case, is not at the codegen layer, it's something that happens higher up the chain (possibly with the readResource call and the state generated) but I have been unable to investigate that since I don't have the correct access to this resource to observe the panic myself.
Yes, but there is no guarantee that any of those imports would lead to the error that we see here, which I can't get to a root cause for because of lack of access to the resource. In any case, I was trying to resolve the panic without diving into multiple other layers when I can't even repro the error. |
Co-authored-by: Luke Hoban <luke@pulumi.com>
Description
This PR is to handle a panic that is caused by a failure during go codegen when using the
pulumi import
command. Unfortunately,import
is impossible to write tests for since it is dependent on a resource existing in a provider. The original PR to add the import command included no tests.I have also been unable to repro this particular failure manually since I do not have the correct access to use the
PushRestrictions
feature forBranchProtection
in Github as I do not have an organization using the team or enterprise tiers.I tested this change by manually adding a panic to the
generateImportedDefinitions
function and observing the resulting output.Related to: #7112
Checklist