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

Catch resource errors #44

Closed

Conversation

jchappell82
Copy link

(Duplicate of closed PR #43, opened against the correct branch)

As I mentioned in #42, here's "enough" code to cause rendering to stop on a resource load failure. The first section at L281 catches server errors and not founds, while the second at 289 should catch things such as the network connection dropping during load, timeouts, etc... (I should point out that I have not yet tested that specific section.)

I don't at all expect this to be merged as is, as it still has a number of things to be addressed. Likely highest on the list is that throwing an error in those event handlers causes an unhandled promise rejection that I spent a pretty long time trying to catch without luck. I'm not sure if it's causing something inside Puppeteer to reject or if it's just something I managed to miss in the Converter code, but as you can see in the convert-svg-to-png change, the only way I was able to get around it for the time being was to add a global unhandledRejection handler. Additionally, when used as a library, I had to add a similar handler to my application to prevent the promise rejection issue as well.

Secondly, I need to write some tests for this, though I was hoping to get the unhandled rejection issue fixed first. If you have any suggestions on that, I'd be happy to dive in a bit more. I'll also rebase/squash this and amend the commit message to match your style once we've settled on some code you're ready to merge.

process.on('unhandledRejection', (e) => {
cli.error(`convert-svg-to-png failed: ${e.stack}`);
process.exit(1);
})
Copy link
Owner

Choose a reason for hiding this comment

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

I don't really like the idea of letting errors bubble up this high. If it's not catchable, I'd rather not through anything.

this[_page].on('requestfailed', (msg) => {
const resource = msg.url();
throw new Error(`Unable to load resource: ${resource}`);
});
Copy link
Owner

Choose a reason for hiding this comment

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

These errors are being thrown within event handlers, so may not be caught by the calling code in the expect async manner. Not sure how easy/clean this is going to be to implement though.

We also need tests added to cover these scenarios.

@neocotic neocotic deleted the branch neocotic:develop April 28, 2022 15:22
@neocotic neocotic closed this Apr 28, 2022
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.

2 participants