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

state: add possible error return to TaskSet.Edge() #6733

Merged
merged 10 commits into from
Apr 25, 2019

Conversation

mvo5
Copy link
Contributor

@mvo5 mvo5 commented Apr 16, 2019

As a followup to the discussion in we had in
#6599
this PR implements an error return in TaskSet.Edge().

The relevant change is in 6426c3b

mvo5 and others added 8 commits March 14, 2019 12:52
The current code in doUpdate works on a bunch of TaskSets like
alias-updates, snap-updates and those are merged into a single
TaskSet in the end. With that the TaskSetEdge information gets
lost. This edge is import for the Remodel() code so we need
to preserve it.

This PR adds a new TaskSet.AddAllWithEdges() and uses it in
doUpdate() to keep the edges informations in the flat TaskSet.
Co-Authored-By: mvo5 <michael.vogt@gmail.com>
As a followup to the discussion in we had in
canonical#6599
this PR implements an error return in TaskSet.Edge().
func (ts TaskSet) Edge(e TaskSetEdge) (*Task, error) {
t, ok := ts.edges[e]
if !ok {
return nil, ErrNoState
Copy link
Collaborator

@pedronis pedronis Apr 16, 2019

Choose a reason for hiding this comment

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

ErrNoState doesn't carry a lot of information, but the usage of Edge will be mostly static (afawk) so I think

fmt.Errorf("internal error: no %q edge in task set", e)  

would be maybe better

Copy link
Collaborator

@pedronis pedronis Apr 17, 2019

Choose a reason for hiding this comment

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

Probably slightly clearer with "missing" instead of "no"

return nil, nil, nil, nil, fmt.Errorf("internal error: cannot find edge task in task set: %v", ts)
edgeTask, err := ts.Edge(snapstate.DownloadAndChecksDoneEdge)
if err != nil {
return nil, nil, nil, nil, fmt.Errorf("internal error: cannot find edge task in task set: %v", err)
Copy link
Collaborator

Choose a reason for hiding this comment

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

then here we could just return err

Copy link
Collaborator

@pedronis pedronis left a comment

Choose a reason for hiding this comment

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

+1 with a question about the tests

c.Assert(ts.Edge(edge2), IsNil)
t, err := ts.Edge(edge1)
c.Assert(t, IsNil)
c.Assert(err, ErrorMatches, fmt.Sprintf("internal error: missing %q edge in task set", edge1))
Copy link
Collaborator

Choose a reason for hiding this comment

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

is the repr strange for the edge? I would have used a `string` in the test

Copy link
Contributor

@stolowski stolowski left a comment

Choose a reason for hiding this comment

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

LGTM

@mvo5 mvo5 merged commit f037189 into canonical:master Apr 25, 2019
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.

3 participants