pulumi / pulumi-java

Java support for Pulumi
Apache License 2.0
64 stars 19 forks source link

Fix emitting `PANIC` in generated programs when we don't have access to the schema of resource properties #1344

Closed Zaid-Ajaj closed 2 months ago

Zaid-Ajaj commented 3 months ago

Description

Fixes #1341

The problem here is when we don't have access to a pulumi schema during program-gen, then currentResourcePropertyType from the generator type is nil. Then at some point we ask for typeName(g.currentResourcePropertyType) and call .String() on the schema type which is nil causing a PANIC to be generated. This PR simply makes sure that currentResourcePropertyType is initialized to a non-nil value to avoid the panic.

That is only half of the problem of #1341 though, because we should have access to the schema when generating examples in the docs. That is however not something we can fix from the point of view of pulumi-java

Checklist

t0yv0 commented 2 months ago

This looks reasonable. I added a lot more tickets today around these PANICS they do not all have the same root cause it appears.

For the root cause that "I don't know the schema here" the provider build use case would actually be lovely to error out with exactly that error message, so we know that we missed a reference to a provider in our build environment.

In addition I seem to hit cases like the one recently fixed in pulumi-random where the AWS provider is referenced in the build environment but at the wrong version (v5 vs v6), so some of the schemas for resources do not load. That'd be nice to know too..

Having actionable warnings is a nice to have of course, for now I just would love to find a way to close out all the actual AWS PANIC issues.

lunaris commented 2 months ago

After digging into the issues that Anton raised, I think that the correct fix for several of them is to error when the schema lookup fails, rather than trying to continue and avoid the panic. Specifically, for:

the examples are incorrect/contain mis-named attributes, which cause the schema lookup failures. This appears to be the approach that other languages take (and indeed, looking at the other language conversions for the examples Anton gave, many fail due to the examples being incorrect). As a result I'm going to raise another PR and recommend we close this one.