Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix panic when resource shape is invalid
Browse files Browse the repository at this point in the history
Zaid-Ajaj committed Nov 14, 2024
1 parent 8e8c6f4 commit bc094eb
Showing 5 changed files with 42 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/Bug Fixes-677.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
component: runtime
kind: Bug Fixes
body: Fix panic when resource shape is invalid
time: 2024-11-15T00:51:03.499599+01:00
custom:
PR: "677"
4 changes: 4 additions & 0 deletions pkg/pulumiyaml/run.go
Original file line number Diff line number Diff line change
@@ -133,6 +133,10 @@ func LoadDir(directory string) (*ast.TemplateDecl, syntax.Diagnostics, error) {
return nil, diags, err
}

if diags.HasErrors() {
return nil, diags, diags
}

packages, err := packages.SearchPackageDecls(directory)
if err != nil {
diags.Extend(syntax.Error(nil, err.Error(), ""))
17 changes: 17 additions & 0 deletions pkg/pulumiyaml/run_test.go
Original file line number Diff line number Diff line change
@@ -1786,6 +1786,23 @@ resources:
requireNoErrors(t, tmpl, diags)
}

func TestUnknownResource(t *testing.T) {
t.Parallel()

const text = `
runtime: yaml
config: {}
variables: {}
resources: {badResource}
outputs: {}`

pt, diags, _ := LoadYAMLBytes("<stdin>", []byte(text))
assert.Nil(t, pt)
assert.Len(t, diags, 1)
assert.True(t, diags.HasErrors())
assert.Contains(t, diags[0].Error(), "resources.badResource must be an object")
}

func TestPoisonResult(t *testing.T) {
t.Parallel()

9 changes: 9 additions & 0 deletions pkg/tests/integration_test.go
Original file line number Diff line number Diff line change
@@ -33,6 +33,15 @@ func TestTypeCheckError(t *testing.T) {
})
}

//nolint:paralleltest // uses parallel programtest
func TestInvalidResourceObject(t *testing.T) {
testWrapper(t, integrationDir("invalid-resource-object"), ExpectFailure, StderrValidator{
f: func(t *testing.T, stderr string) {
assert.Contains(t, stderr, "resources.badResource must be an object")
},
})
}

//nolint:paralleltest // uses parallel programtest
func TestMismatchedConfigType(t *testing.T) {
testWrapper(t, integrationDir("mismatched-config-type"), ExpectFailure, StderrValidator{
6 changes: 6 additions & 0 deletions pkg/tests/testdata/invalid-resource-object/Pulumi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
name: myymltest
description: A minimal Pulumi YAML program
runtime: yaml
variables: {}
resources: {badResource}
outputs: {}

0 comments on commit bc094eb

Please sign in to comment.