Skip to content

Resolve validation error #3634

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

Merged
merged 1 commit into from
Jun 20, 2025

Conversation

Horiodino
Copy link
Contributor

This PR enhances the limayaml.Validate() function to collect and return all validation errors found in a Lima template, instead of stopping at the first encountered error.

Fixes: #3606

Updated the validation logic to accumulate multiple validation errors.

@Horiodino Horiodino force-pushed the resolve-validation-error branch from e095c93 to 7c55bd8 Compare June 17, 2025 12:23
@Horiodino Horiodino force-pushed the resolve-validation-error branch 2 times, most recently from 7fac679 to 7b24bcd Compare June 18, 2025 16:28
@alexandear alexandear requested a review from Copilot June 19, 2025 08:57
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the validation logic to accumulate all errors found in a Lima YAML template and return them together, rather than bailing out at the first error. Tests are adjusted to verify substrings in the combined error message.

  • Replace single-error returns with errors.Join accumulation in Validate, validateFileObject, and part of validateNetwork
  • Wrap the aggregated errors at the end of Validate with a "validation failed: %w" prefix
  • Update unit tests to use assert.ErrorContains when expecting error messages

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/limayaml/validate.go Switched early return calls to error accumulation; added final wrapping of all errors
pkg/limayaml/validate_test.go Changed assertions from assert.Error to assert.ErrorContains
Comments suppressed due to low confidence (1)

pkg/limayaml/validate_test.go:19

  • Add a new test where multiple invalid fields are set simultaneously, and assert that Validate returns all errors to ensure aggregation behaves as expected.
func TestValidateProbes(t *testing.T) {

@Horiodino Horiodino force-pushed the resolve-validation-error branch from 7b24bcd to b9dd5cf Compare June 19, 2025 09:42
@Horiodino Horiodino force-pushed the resolve-validation-error branch from b9dd5cf to 6cc671d Compare June 19, 2025 10:37
@@ -86,7 +87,7 @@ additionalDisks:
assert.NilError(t, err)

err = Validate(y, false)
assert.Error(t, err, "field `additionalDisks[0].name is invalid`: identifier must not be empty")
assert.ErrorContains(t, err, "field `additionalDisks[0].name is invalid`: identifier must not be empty")
Copy link
Member

Choose a reason for hiding this comment

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

please revert:

Suggested change
assert.ErrorContains(t, err, "field `additionalDisks[0].name is invalid`: identifier must not be empty")
assert.Error(t, err, "field `additionalDisks[0].name is invalid`: identifier must not be empty")

@Horiodino Horiodino force-pushed the resolve-validation-error branch from 6cc671d to 67d1d7e Compare June 19, 2025 16:45
Signed-off-by: Horiodino <holiodin@gmail.com>

updatec test-cases

Signed-off-by: Horiodino <holiodin@gmail.com>

using err.join

Signed-off-by: Horiodino <holiodin@gmail.com>
@Horiodino Horiodino force-pushed the resolve-validation-error branch from 67d1d7e to 69f223f Compare June 20, 2025 06:43
@AkihiroSuda AkihiroSuda added this to the v1.1.2 milestone Jun 20, 2025
Copy link
Member

@jandubois jandubois left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM

@jandubois jandubois merged commit eb46f74 into lima-vm:master Jun 20, 2025
38 checks passed
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.

limayaml.Validate() only returns the first validation error
4 participants