pulumi / pulumi-yaml

YAML language provider for Pulumi
Apache License 2.0
39 stars 12 forks source link

Improve non-existent field error message by checking if the field fits into the child object #560

Open iwahbe opened 6 months ago

iwahbe commented 6 months ago

Hello!

Issue details

Building on top of #559, we currently (correctly) error when user's specify an invalid property for an object. If the invalid field specified is valid in a directly nested object, we should suggest that the user nests it.

For example:

  service:
    type: gcp:cloudrun:Service
    properties:
      location: us-central1
      template:
        containers:
          - image: "gcr.io/cloudrun/hello"
    Error: Property containers does not exist on 'gcp:cloudrun/ServiceTemplate:ServiceTemplate'
      on Pulumi.yaml line 13:
      13:         containers:
      14:           - image: "gcr.io/cloudrun/hello"
    Cannot assign '{location: string, template: {containers: List<{image: string}>}}' to 'gcp:cloudrun/service:Service':      template: Cannot assign '{containers: List<{image: string}>}' to 'gcp:cloudrun/ServiceTemplate:ServiceTemplate':
        Existing properties are: metadata, spec

We should also suggest that containers is a property of spec:

    Error: Property containers does not exist on 'gcp:cloudrun/ServiceTemplate:ServiceTemplate'
      on Pulumi.yaml line 13:
      13:         containers:
      14:           - image: "gcr.io/cloudrun/hello"
    Cannot assign '{location: string, template: {containers: List<{image: string}>}}' to 'gcp:cloudrun/service:Service':      template: Cannot assign '{containers: List<{image: string}>}' to 'gcp:cloudrun/ServiceTemplate:ServiceTemplate':
        Existing properties are: metadata, spec
        'containers' is a property of 'spec': consider nesting 'containers' under 'spec':
      spec:
        containers:
          - image: "gcr.io/cloudrun/hello"
    ```


### Affected area/feature

<!-- If you know the specific area where this feature request would go (e.g. Automation API, the Pulumi Service, the Terraform bridge, etc.), feel free to put that area here.  -->