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

Expose meaningful error text from yamlpatch #5273

Conversation

TBBle
Copy link
Contributor

@TBBle TBBle commented Jan 22, 2021

Fixes: #5259

Description

The faulty JSONPatch tests now ensure that the resulting error message actually mentions the faulty value.

User facing changes (remove if N/A)

Per #5259, any failure from yamlpatch simply logs

invalid path:

even if the path itself was valid.

Now, for the example given there, we get

Unexpected op: delete

Other example errors I got while messing with that file to introduce different errors:

Unable to remove nonexistent key: service.ports

yamlpatch remove operation does not apply: doc is missing path: /deploys/helm/releases/0/setValues/service.port

yamlpatch add operation does not apply: doc is missing path: /deploys/helm/releases/0/setValues/service.port

The existing unit-test outputs

yamlpatch replace operation does not apply: doc is missing key: /unknown

Note that I don't have an example of the "known to panic" case mentioned in the tryPatch documentation, so that still returns the same error text as previously.

The faulty JSONPatch tests now ensure that the resulting error message
actually mentions the faulty value.

Fixes: GoogleContainerTools#5259

Signed-off-by: Paul "Hampy" Hampson <p_hampson@wargaming.net>
@google-cla

This comment has been minimized.

@google-cla google-cla bot added the cla: no label Jan 22, 2021
@TBBle

This comment has been minimized.

@google-cla

This comment has been minimized.

@TBBle

This comment has been minimized.

@codecov
Copy link

codecov bot commented Jan 22, 2021

Codecov Report

Merging #5273 (e3ac811) into master (0341576) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #5273   +/-   ##
=======================================
  Coverage   71.92%   71.92%           
=======================================
  Files         389      389           
  Lines       14149    14149           
=======================================
  Hits        10176    10176           
  Misses       3226     3226           
  Partials      747      747           
Impacted Files Coverage Δ
pkg/skaffold/schema/profiles.go 89.61% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0341576...e3ac811. Read the comment docs.

@gsquared94 gsquared94 added kokoro:force-run forces a kokoro re-run on a PR and removed cla: no labels Jan 25, 2021
@kokoro-team kokoro-team removed the kokoro:force-run forces a kokoro re-run on a PR label Jan 25, 2021
@gsquared94

This comment has been minimized.

@google-cla

This comment has been minimized.

@google-cla google-cla bot added the cla: no label Jan 25, 2021
@googlebot

This comment has been minimized.

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@googlebot googlebot added cla: yes and removed cla: no labels Feb 5, 2021
@gsquared94
Copy link
Contributor

@TBBle the CLA issue seems to have been fixed. Can you rebase on latest master and publish the PR if you think it's ready for a review?

@TBBle
Copy link
Contributor Author

TBBle commented Feb 8, 2021

I just need to get sign-off from my end (internal company policy), and I'll rebase this once that happens. Hopefully tomorrow.

Copy link
Contributor

@tejal29 tejal29 left a comment

Choose a reason for hiding this comment

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

Also adding these instructions to our Development guide here #5375

defer func() {
if errPanic := recover(); errPanic != nil {
valid = false
err = fmt.Errorf("invalid path: %s", patch.Path)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please create a new error code for this use case and

Add a Distinct Err Code in proto/skaffold.proto e.g. INIT_INVALID_PROFILE_PATCH,

Here "INIT" stands for the phase initialization.
run ./hack/generate_proto.sh
You can use the new sError.NewError to create errors with the distinct error code you just defined e.g

return sErrors.NewError(err,
		proto.ActionableErr{
			Message: fmt.Sprintf("invalid path %s", patch.Path),
			ErrCode: proto.StatusCode_ INIT_INVALID_PROFILE_PATCH,
                         Suggestions: []*proto.Suggestion{
				{
					SuggestionCode: proto.SuggestionCode_FIX_PATCH_FILE,
					Action:         "Please fix a valid patch file and try again",
				},
			},
		})

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be clear, this is not a new error, this was the pre-existing error. If I'm going to change it, it'll become "yamlpatch panic'd", or I'll just wrap up errPanic, since I have no test case for this.

Copy link
Contributor

Choose a reason for hiding this comment

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

ACK. we are trying to collect distinct errors that happen during skaffold run and adding an error code will help us

@tejal29
Copy link
Contributor

tejal29 commented Feb 16, 2021

I just need to get sign-off from my end (internal company policy), and I'll rebase this once that happens. Hopefully tomorrow.

Were you able to get a sign off ?

@TBBle
Copy link
Contributor Author

TBBle commented Feb 17, 2021

I haven't had a chance to come back and make the requested changes yet. Hopefully later this week, otherwise it'll be next week.

@nkubala
Copy link
Contributor

nkubala commented Mar 8, 2021

@TBBle any updates here? would love to get this merged

@TBBle
Copy link
Contributor Author

TBBle commented Mar 8, 2021

Oops, this slipped past me last week. I should be able to get it done this week.

@MarlonGamez
Copy link
Contributor

hey @TBBle , just want to check in on this again :)

@TBBle
Copy link
Contributor Author

TBBle commented Apr 16, 2021

Ooops, sorry. I must have marked this 'read' by accident. I do still plan to come back and recreate this PR.

@gsquared94
Copy link
Contributor

Closing this for now. Please reopen when you're able to @TBBle

@gsquared94 gsquared94 closed this May 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Profile patch with invalid op reports "invalid path" instead of "invalid op"
7 participants