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

add a simple way to collect cancel errors #295

Closed
mvdan opened this issue Apr 7, 2019 · 0 comments
Closed

add a simple way to collect cancel errors #295

mvdan opened this issue Apr 7, 2019 · 0 comments
Milestone

Comments

@mvdan
Copy link
Contributor

mvdan commented Apr 7, 2019

For example, cancelling a target context can close its tab, or shutdown the entire browser. The cancel() call blocks until whichever action is finished, meaning that we don't leak resources like files ondisk.

However, those actions can cause errors. Right now, some are ignored, and some others are just logged. We should instead allow the user to collect them.

We can't add this to cancel() directly, as the signature is fixed by the context package.

I can think of multiple options. The first is to add a field to the Context type, so that then one can do:

cancel()
if err := chromedp.FromContext(ctx).Error; err != nil {
     // ...

A similar way would be to add an API to grab the error from the context:

cancel()
if err := chromedp.Error(ctx); err != nil {
     // ...

Another way would be to hijack the context.Context.Err() method, but it's documented to only return nil or one of the few standard context errors. This would also break if anyone layers a context on top of ours. Still, the API would be nice, if we can look past the weird semantics:

cancel()
if err := ctx.Err(); err != nil {
     // ...
@mvdan mvdan added this to the v0.2.0 milestone Apr 7, 2019
@mvdan mvdan closed this as completed in b481eea Apr 8, 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

No branches or pull requests

1 participant