Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

gps: use golang.org/x/sync/errgroup #1155

Merged
merged 1 commit into from
Sep 13, 2017
Merged

gps: use golang.org/x/sync/errgroup #1155

merged 1 commit into from
Sep 13, 2017

Conversation

tamird
Copy link
Contributor

@tamird tamird commented Sep 11, 2017

...instead of custom code that does the same thing. Return
informative errors rather than logging directly (into the abyss).

Also remove sourceFailure{,s} while I'm here, which are unnecessary.

What does this do / why do we need it?

Includes more information in errors which bubble up in tests, for one.

What should your reviewer look out for in this PR?

Not much, pretty straightforward.

Do you need help or clarification on anything?

No.

Which issue(s) does this PR fix?

None.

@sdboyer
Copy link
Member

sdboyer commented Sep 11, 2017

heh - sourceSetupFailure was originally intended to be part of a broader nuanced error case handling scheme, which i still have not had time to revisit :( that, and, before we were using pkg/errors in gps.

i realize we've got these scattered around elsewhere, but before merging this, can someone clarify a bit for me on whether it's a design goal of pkg/errors that errors should be wrapped multiple times as they're passed back up the stack, and/or where the "optimal" point to wrap errs in a stack is supposed to be?

@tamird
Copy link
Contributor Author

tamird commented Sep 11, 2017

Yes, multiple levels of wrapping is the intention, so that you can reconstruct all the handlers of the error. Note that errors.Cause is iterative and unwraps until there's no more "cause" left: https://github.com/pkg/errors/blob/master/errors.go#L256

@jmank88
Copy link
Collaborator

jmank88 commented Sep 11, 2017

You're right, we should be using WithMessage when the error already has a stacktrace.

@tamird
Copy link
Contributor Author

tamird commented Sep 11, 2017 via email

ident: mb.getURL(),
err: err,
})
errs = append(errs, errors.Wrapf(err, "failed to set up %q", mb.getURL()))
Copy link
Collaborator

Choose a reason for hiding this comment

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

errors.WithMessage is cheaper in cases like this too, when we don't need the stack trace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not going to make that optimization; it doesn't matter and will be net-negative the very first time someone looks to find where this error originates.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Doesn't the same logic apply to removing sourceFailures?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How? sourceFailures provides nothing at all.

Copy link
Collaborator

@jmank88 jmank88 Sep 11, 2017

Choose a reason for hiding this comment

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

Before this change the final cause in the chain of errors was a sourceFailures with all of its errors preserved, so fiddling with the error at the top level, or with the format verb, could potentially provide some insight.

Now it's an errors.New() with only the string messages of the original errors, so they'll have to come here to edit this method directly to follow the trail any deeper.

An improved version of sourceFailures might implement fmt.Formatter (or be generalized into a multiError{causes, msg}), but I think it's still offering something as-is.

@jmank88
Copy link
Collaborator

jmank88 commented Sep 11, 2017

Eh, not true. If you print stack traces (%+v), you'll get them all.

True, that may be useful in some cases. I was particularly thinking about cases like unwrapVcsError though.

@tamird tamird changed the title gps: include info in error messages rather than logging gps: use golang.org/x/sync/errgroup Sep 12, 2017
@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

@jmank88 alright well, you convinced me. I've rewritten that area of the code since the error handling there bothered me O.o

@sdboyer
Copy link
Member

sdboyer commented Sep 12, 2017

eek. could you do a dep prune, to see what we can strip out of the additional dependency, then amend the most recent commit? (i realize we haven't been pruning up until now, but i'd like to start -and if we can avoid additional bits in that most recent commit ever having to enter the history, it'd be a win.)

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

Done.

p := lps[resp.i]
logger.Printf("(%d/%d) %s %s@%s\n", cnt, len(lps), msg, p.Ident(), p.Version())
}
logger.Printf("(%d/%d) %s %s@%s\n", atomic.AddUint32(&cnt, 1), len(lps), msg, p.Ident(), p.Version())
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these technically racing to log after the atomic add (meaning they could reorder)? Would the op have to be crammed inside a fmt.Formatter to get around that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, they might reorder. I'm not sure fmt.Formatter would do it, because there's still a race in the machinery that ends up calling Write with the result.

We could do it under our own lock, though.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What about moving the sem stuff into the body of err func()? Then another lock here is not such a big deal.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't follow. What does the semaphore have to do with anything?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Then another worker is freed before we potentially lock for this count, or even now before the logger locks internally.

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017 via email

@jmank88
Copy link
Collaborator

jmank88 commented Sep 12, 2017

errgroup is neat. I think we'll find a few other places to swap it right in.

Hopefully wiring through that Context to fix the build isn't too deep of a rabbit hole

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017 via email

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

Urgh, validate-vendor doesn't like pruning. Fixed.

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

Also added a mutex as we discussed.

@sdboyer
Copy link
Member

sdboyer commented Sep 12, 2017

Urgh, validate-vendor doesn't like pruning. Fixed.

yeah, i was just fixing this locally, actually. maybe hold a sec on it

@sdboyer
Copy link
Member

sdboyer commented Sep 12, 2017

that'll be #1161

@sdboyer
Copy link
Member

sdboyer commented Sep 12, 2017

should be a pretty straightforward rebase now, though probably not entirely conflict-free

...instead of custom code that does the same thing. Return
informative errors rather than logging directly (into the abyss).

Also remove sourceFailure{,s} while I'm here, which are unnecessary.

Also `dep prune` real quick.
@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017 via email

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

Green.

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

codeclimate is grumpy because I added a context.TODO() but I looked up the stack and didn't see an opportunity to plumb an existing one. I'll look again.

@sdboyer
Copy link
Member

sdboyer commented Sep 12, 2017

i can't recall if there's an opportunity for one higher up, but it's fair to say that in general our wiring of Context through the SourceManager system is...incomplete. so, don't look too hard :)

@sdboyer
Copy link
Member

sdboyer commented Sep 12, 2017

gonna do a proper grok & review this evening

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017 via email

@tamird
Copy link
Contributor Author

tamird commented Sep 12, 2017

(So I'm going to leave it as-is)

@sdboyer
Copy link
Member

sdboyer commented Sep 13, 2017

yepyepyepyep 🎉 🎉

@sdboyer sdboyer merged commit eac1f47 into golang:master Sep 13, 2017
@tamird tamird deleted the simplify-errors branch September 13, 2017 01:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants