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

When overlay fails expects, report position of matches #91

Merged
merged 2 commits into from
Feb 14, 2020

Conversation

pivotaljohn
Copy link
Contributor

@pivotaljohn pivotaljohn commented Feb 8, 2020

(this is a sketch, intended to spark dialogue and critique)

aimed at #76

@@ -66,7 +66,12 @@ func (a ArrayItemMatchAnnotation) Indexes(leftArray *yamlmeta.Array) ([]int, err
return nil, err
}

return idxs, a.expects.Check(len(idxs))
nodes := MatchingNodes{}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cppforlife one "draft" aspect of the PR is that — all things being equal — would expect MatchNodes to return the collection of matching nodes. However, there is downstream logic that expects a collection of indexes.

A question I'm exploring: what made passing around indexes of matches a suitable tactic, to date? ... does this PR/feature now make passing around references more suitable (or not)?

Copy link
Contributor

@cppforlife cppforlife Feb 10, 2020

Choose a reason for hiding this comment

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

indexes are used to reference a node within its parent (eg array item within array). since things can be removed you need stable ref to what to remove.

@jtigger
Copy link
Contributor

jtigger commented Feb 11, 2020

@cppforlife this PR is ready for a proper review / merge (I don't have permissions to mark it as ready for review).

@pivotaljohn pivotaljohn marked this pull request as ready for review February 11, 2020 18:53

expectedErr := "Overlaying (in following order: overlay.yml): " +
"Document on line overlay.yml:4: " +
"Expected number of matched nodes to be 1, but was 2\n" +
Copy link
Contributor

Choose a reason for hiding this comment

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

we should probably just use parenthesis with commas (e.g. but was 2 (line tpl.yml:2, line tpl.yml:6)). multiline errors for now arent formatted properly in nested errors.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I invested the least attention to this aspect having no real idea of what would work. The format you suggest reads better than one-per-line.

if lastErr == nil {
return nil
}
}
return lastErr
}

func formatPositions(pos []*filepos.Position) string {
Copy link
Contributor

Choose a reason for hiding this comment

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

lets place formatPositions on MatchAnnotationExpectsKwarg. you can use func (MatchAnnotationExpectsKwarg) formatPositions(... sig with naming MatchAnnotationExpectsKwarg.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, not sure why I didn't do that: it's an implementation detail of #Check().

@cppforlife
Copy link
Contributor

left a few comments. otherwise look good.

... to keep nested errors readable -- multiline output breaks formatting.

- and scope `formatPositions()` as a member function of `MatchAnnotationExpectsKwarg`:
  it is an implementation detail of output from `Check()`.
@cppforlife cppforlife merged commit a3c0f3d into carvel-dev:master Feb 14, 2020
@cppforlife
Copy link
Contributor

merged. minor fixes added: a3c0f3d...1227be5

@jtigger jtigger deleted the list-overlay-matches branch February 20, 2020 05:23
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.

None yet

3 participants