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

Use InputPropertyError for validations in the node group components #1592

Merged
merged 3 commits into from
Jan 24, 2025

Conversation

flostadler
Copy link
Contributor

@flostadler flostadler commented Jan 22, 2025

pu/pu introduced new error types for component authors to use. The InputPropertyError and InputPropertiesError errors are pretty printed by the engine and don't confuse users with a load of GRPC stack traces (see docs). Additionally those errors accumulate multiple validation errors and allow presenting them all to users. Previously we exited on the first error.

For adding EFA support (#1564) we'd like to make use of these new errors. In preparation for that I've updated the node group components to make use of this new error type.

UX:

Old (missing the second error):
Screenshot 2025-01-23 at 11 01 38
New:
Screenshot 2025-01-23 at 10 59 25

@flostadler
Copy link
Contributor Author

flostadler commented Jan 22, 2025

Copy link

Does the PR have any schema changes?

Looking good! No breaking changes found.
No new resources/functions.

@flostadler flostadler self-assigned this Jan 22, 2025
@flostadler flostadler requested review from t0yv0, corymhall and a team January 22, 2025 15:34
@flostadler flostadler marked this pull request as ready for review January 22, 2025 15:34
Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Can you add screenshots of before and after error messages to the PR? I'm especially interested in what it looks like for errors that are due to the interaction between multiple properties.

nodejs/eks/nodes/ami.ts Show resolved Hide resolved
`an instanceProfile or instanceProfileName is required`,
parent,
);
throw new pulumi.InputPropertyError({
Copy link
Contributor

Choose a reason for hiding this comment

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

In these cases where the error could be attributed to multiple properties should we add two property errors or should it stay as a resource error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like a single input property error is enough here.
The benefit of the input property error is that a user will be presented with all errors and not only the first validation that failed.

For example compare those two errors for the same program:

Old:
Screenshot 2025-01-23 at 11 01 38
New:
Screenshot 2025-01-23 at 10 59 25

IMO we shouldn't create multiple errors for the same issue when there's multiple properties involved. That's just gonna increase the cognitive complexity of understanding the issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

ah I see. I wasn't sure how the property errors would be shown, but since they are just listed out under the resource then that makes total sense.

It looks like that value {{urn:pulumi:..} is something that the engine adds? I'm assuming it only works with primitive types or something?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's how dependency resources are visualized here. I guess the URN is the only sensible value that can be shown here 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, does it resolve Output values correctly? Wondering if we ever need to be careful about what kind of values we can include here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean the message the engine adds, right? No, this one shows either that it's an output (e.g. during preview) or the resolved value if it's already resolved.

Copy link
Contributor

@corymhall corymhall left a comment

Choose a reason for hiding this comment

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

Looks good, just a couple of questions for my own interest.

Do you know if there is a guide anywhere on these new error types? Looking at the linked docs it doesn't look like there is any info on how to use (i.e. my questions on this PR)

);
const validationErrors: pulumi.InputPropertyErrorDetails[] = [];

const instanceProfileName = core.apply((c) => resolveInstanceProfileName(args, c));
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens when you throw inside of an apply? Do we still get the rest of the validation errors unless they depend on instanceProfileName? And if we eventually do throw because of other errors do these get surfaced then?

`invalid args for node group ${name}, nodeSecurityGroup and nodeSecurityGroupId are mutually exclusive`,
parent,
);
validationErrors.push({
Copy link
Contributor

Choose a reason for hiding this comment

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

If we no longer throw here and keep going, can that lead to us being in a bad place? When we use validation errors like this, do we need to make sure we throw validation errors before any resources are created?

In this case I think we do throw before creating resources, but I'm just curious for future reference.

`an instanceProfile or instanceProfileName is required`,
parent,
);
throw new pulumi.InputPropertyError({
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, does it resolve Output values correctly? Wondering if we ever need to be careful about what kind of values we can include here.

Base automatically changed from flostadler/clean-provider-internals to master January 24, 2025 13:54
@flostadler flostadler force-pushed the flostadler/proper-errors branch from 8aea025 to 929ccdc Compare January 24, 2025 13:55
@flostadler flostadler merged commit 3f7f18c into master Jan 24, 2025
5 checks passed
@flostadler flostadler deleted the flostadler/proper-errors branch January 24, 2025 13:56
@pulumi-bot
Copy link
Contributor

This PR has been shipped in release v3.8.0.

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.

3 participants