fix: allow only map and sequence essential field#267
fix: allow only map and sequence essential field#267lczyk wants to merge 8 commits intocanonical:mainfrom
essential field#267Conversation
|
letFunny
left a comment
There was a problem hiding this comment.
Thank you for this @lczyk, indeed we paid so much attention to get the error messages right for list and map that we didn't catch the case when the node is neither. I added a suggestion to change the error message to follow the convention and then this is good to go.
|
spoke with @upils and while this fixes the bug, the validation behind the scenes is a bit of a spaghetti and so the error message is not quite as pleasant as we might wish it were. ideally it'd be i've fixed the tests to pass with the sub-optimal error message just so the PR is good, but @upils might end up rolling their own PR to try to make the error messages better 👍 |
|
i've had to adjust |
|
Last time @upils and rest of the team agreed that we want to stop having a complex test processing step and instead we want to have individual tests. What about adding a test for format |
|
@letFunny This is a format-independent test, so there is little point in writing 2 tests. Duplicated test will have to be tracked down when we is removed |
Yes, indeed, which is why it doesn't matter if it is tested with This works: diff --git a/internal/setup/setup_test.go b/internal/setup/setup_test.go
index 95a3d5b..608b0f0 100644
--- a/internal/setup/setup_test.go
+++ b/internal/setup/setup_test.go
@@ -3728,6 +3728,18 @@ var setupTests = []setupTest{{
`,
},
relerror: `cannot parse package "mypkg": essential expects a list`,
+}, {
+ summary: "Essential must be list or map",
+ input: map[string]string{
+ "chisel.yaml": strings.ReplaceAll(testutil.DefaultChiselYaml, "format: v1", "format: v3"),
+ "slices/mydir/mypkg.yaml": `
+ package: mypkg
+ essential: not-a-list-or-map
+ slices:
+ myslice:
+ `,
+ },
+ relerror: `cannot parse package "mypkg" slice definitions: cannot decode essential field`,
}, {
summary: "Format v1/v2 expect a list in 'essential' (slice)",
input: map[string]string{
diff --git a/internal/setup/yaml.go b/internal/setup/yaml.go
index b048bfc..04f4950 100644
--- a/internal/setup/yaml.go
+++ b/internal/setup/yaml.go
@@ -95,6 +95,8 @@ func (es *yamlEssentialListMap) UnmarshalYAML(value *yaml.Node) error {
if err != nil {
return err
}
+ default:
+ return fmt.Errorf("cannot decode essential field")
}
es.Values = m
return nilAnd it is much more simple, wouldn't you agree? This is commit e68b152, credit where credit is due. |
I agree it should not matter and we know we can test only for I also agree with the approach discussed with Gustavo. I assume that when we rework this:
So with these assumptions in mind, I thought declaring this new test as a format-agnostic test made the intent clearer. In the end I am fine with either solutions because anyway all tests will have to be carefully reviewed when simplifying that, so one more test maybe not in the right "group" might not be a big deal. |
error if
essentialfield is not a sequence or a mapsee feat(26.04): introduce v3 format chisel-releases#903 (comment)
Have you signed the CLA?