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

Improve error message for invalid enum values on pulumi convert #11019

Merged
merged 1 commit into from Dec 2, 2022

Conversation

aq17
Copy link
Contributor

@aq17 aq17 commented Oct 13, 2022

Fixes #10814

Currently if an invalid enum value is provided, (nil, true) is returned here. On pulumi convert, we still try to translate the PCL to the resulting language here, causing an unhelpful error message (PANIC=Format method: runtime error: invalid memory address or nil pointer dereference) to be injected into the invalid program text (example in #10814).

This change improves it a bit so that the valid enum values are provided in the error message, i.e. (PANIC=Format method: fatal: A failure has occurred: Invalid enum provided: valid values are [Block Append])

@pulumi-bot
Copy link
Contributor

pulumi-bot commented Oct 13, 2022

Changelog

[uncommitted] (2022-12-01)

Bug Fixes

  • [programgen] Improve error message for invalid enum values on pulumi convert.
    #11019

@aq17 aq17 changed the title Conversion fails on resources with inputs named type Improve error message for invalid enum values on pulumi convert Nov 30, 2022
@aq17 aq17 requested a review from iwahbe November 30, 2022 23:05
@iwahbe
Copy link
Member

iwahbe commented Nov 30, 2022

Instead of panicking, can we emit the raw value ("block" in the case of #10814) and a diagnostic error explaining what went wrong?

@iwahbe
Copy link
Member

iwahbe commented Nov 30, 2022

I think the simplest solution would be to call unsafeEnum and return a diagnostic explaining the problem. We can then update our generators to report that diagnostic.

@aq17 aq17 force-pushed the aqiu/10814 branch 3 times, most recently from cd4a7ef to 5cb5aba Compare December 1, 2022 00:55
pkg/codegen/pcl/binder_schema.go Outdated Show resolved Hide resolved
pkg/codegen/pcl/binder_schema.go Outdated Show resolved Hide resolved
@aq17 aq17 requested a review from iwahbe December 1, 2022 19:22
@aq17 aq17 marked this pull request as ready for review December 1, 2022 19:25
Copy link
Member

@iwahbe iwahbe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some nits left, but it looks good otherwise. LGTM!

(Conditional on 🟢 tests of course)

pkg/codegen/pcl/binder_schema.go Outdated Show resolved Hide resolved
pkg/codegen/pcl/binder_schema_test.go Outdated Show resolved Hide resolved
@aq17
Copy link
Contributor Author

aq17 commented Dec 2, 2022

bors merge

@bors
Copy link
Contributor

bors bot commented Dec 2, 2022

Build succeeded:

@bors bors bot merged commit 2f23c0f into master Dec 2, 2022
@bors bors bot deleted the aqiu/10814 branch December 2, 2022 18:16
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.

Conversion fails on resources with inputs named type
3 participants