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

Fix diagnostic messages on update environment #422

Merged
merged 1 commit into from
Dec 12, 2024

Conversation

seanyeh
Copy link
Contributor

@seanyeh seanyeh commented Dec 9, 2024

Fixes #370

When updating an env with an invalid definition, UpdateEnvironmentWithRevision should return no error but with diagnostics

Testing

Because of this issue, we previously wouldn't reach here (which requires non-error but with diagnostics), but with this change, now we can, because UpdateEnvironmentWithRevision will now return no error but with diagnostics on invalid definitions

When updating an env with an invalid definition:

Before:

❯ go run ./cmd/esc env edit test3/abc/ghi
Error: updating environment definition: [0]
Diags: yaml: line 2: mapping values are not allowed in this context

exit status 1

Now:

❯ go run ./cmd/esc env edit test3/abc/ghi
Error: yaml: line 2: mapping values are not allowed in this context

Press ENTER to continue editing or ^D to exit

@seanyeh seanyeh force-pushed the syeh/fix-update-env-diags branch from 3dca0e6 to 1cdee31 Compare December 9, 2024 22:07
@@ -560,7 +560,7 @@ func (pc *client) UpdateEnvironmentWithRevision(
})
if err != nil {
var diags *EnvironmentErrorResponse
if errors.As(err, &diags) && diags.Code == http.StatusBadRequest && len(diags.Diagnostics) != 0 {
if errors.As(err, &diags) && (diags.Code == http.StatusBadRequest || len(diags.Diagnostics) != 0) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is because on certain 4xx errors, the pulumi service returns an object without {..., "code": 4xx}

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, should we fix this in PS? Sounds like it's not following a required API contract?

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 initially considered this but I think it's a much bigger lift - we follow this "pattern" in many routes where certain errors will return code and message by default, but otherwise not.

I think perhaps a better fix is to check the http response status code instead. @pgavlin I notice that we don't return the http response on 4xx/5xx errors, is this intentional?

@seanyeh seanyeh force-pushed the syeh/fix-update-env-diags branch from 1cdee31 to cf8b473 Compare December 9, 2024 22:25
@seanyeh seanyeh marked this pull request as ready for review December 9, 2024 22:29
@seanyeh seanyeh requested review from a team and IaroslavTitov December 9, 2024 22:30
CHANGELOG_PENDING.md Show resolved Hide resolved
@@ -560,7 +560,7 @@ func (pc *client) UpdateEnvironmentWithRevision(
})
if err != nil {
var diags *EnvironmentErrorResponse
if errors.As(err, &diags) && diags.Code == http.StatusBadRequest && len(diags.Diagnostics) != 0 {
if errors.As(err, &diags) && (diags.Code == http.StatusBadRequest || len(diags.Diagnostics) != 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, should we fix this in PS? Sounds like it's not following a required API contract?

cmd/esc/cli/client/client_test.go Outdated Show resolved Hide resolved
@seanyeh seanyeh force-pushed the syeh/fix-update-env-diags branch from cf8b473 to bf047fa Compare December 12, 2024 20:44
@seanyeh seanyeh force-pushed the syeh/fix-update-env-diags branch from bf047fa to 0136bbb Compare December 12, 2024 21:12
@seanyeh seanyeh merged commit e9e5988 into main Dec 12, 2024
6 checks passed
@seanyeh seanyeh deleted the syeh/fix-update-env-diags branch December 12, 2024 22:40
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.

UpdateEnvironmentWithRevision does not return diagnostics properly
2 participants