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

Expose TimeoutError#request #299

Merged

Conversation

ulken
Copy link
Contributor

@ulken ulken commented Nov 6, 2020

Closes #298

@ulken
Copy link
Contributor Author

ulken commented Nov 6, 2020

Hum, I'll look into the error later today. Can't see exactly why the changes would introduce that error, but I'll have to dig into it.

@ulken
Copy link
Contributor Author

ulken commented Nov 6, 2020

The failure has been around for a while?

First showed up here and has been failing consistently since?

How come it's not been fixed and/or was merged?

@sholladay
Copy link
Collaborator

That error is caused by changes in the node-fetch dev dependency, not by any changes in Ky itself. It doesn't affect end users and we just haven't gotten around to it. Would be nice to fix it.

@ulken
Copy link
Contributor Author

ulken commented Nov 6, 2020

Alright. Do we know exactly what change caused it? What are we looking for? Do we want to keep the current error message intact? Any pointers if I were to look into it?

@sholladay
Copy link
Collaborator

sholladay commented Nov 6, 2020

Just update the assertion so the expected message matches the actual message that is output. They just added Failed to execute \'fetch\' on \'Window\': to it.

@ulken
Copy link
Contributor Author

ulken commented Nov 7, 2020

This PR or a separate one?

@sholladay
Copy link
Collaborator

I'm fine with it either way. But a separate PR would make some people happy, so let's go with that if you have the time.

@ulken
Copy link
Contributor Author

ulken commented Nov 7, 2020

@sholladay #300

@ulken ulken force-pushed the 298-expose_request_timeout_error branch from 9b7872d to 6182fe8 Compare November 7, 2020 23:20
test/browser.js Outdated
const error = await page.evaluate(url => {
const request = window.ky(`${url}/slow`, {timeout: 500}).text();
request = window.ky(`${url}/slow`, {timeout: 500}).text();
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can't transfer objects between runtimes like this. The callback given to page.evaluate() is basically converted to a string and sent over the network. It's executed in a different scope. Puppeteer is able to serialize certain things in the arguments and return value, but you can't assign to an outer variable like this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, wow. Not being familiar with Puppeteer, I find that extremely surprising. By just looking at the code snippet in isolation it's not intuitive at all. But as always, you should know what you're running, I guess.

Nevertheless, nice catch. Classic mistake of skipping the red part of red-green-refactor...

Anyhow, I'll revert the changes to this test. Do you want me to add a new test file for TimeoutError instead?

Side-note: did you see my comments in #300 regarding node-fetch? Do you buy it or care to convince me otherwise?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's your take on the above?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Not being familiar with Puppeteer, I find that extremely surprising.

Yeah, I hear you. It's just sort of the nature of true browser testing, unlike the fake browser-like environments some people try to create in Node, e.g. JSDOM. It blew my mind when I first started doing browser testing with Selenium years ago, which has a commonly used equivalent to page.evaluate(). One clue that could tell you what's going on is if we use browser APIs in there, like addEventListener(). I suppose Deno is blurring that line though since it's adopting many of those APIs, so in the future it may be even harder to tell what's going on

Anyhow, I'll revert the changes to this test. Do you want me to add a new test file for TimeoutError instead?

No, I think it would be better to update the evaluate callback in this test to return a plain object instead of the error.toString() directly. You can then attach properties to that object for whatever you want to assert about outside of the evaluate callback. Puppeteer will serialize that object. IIRC, the reason we aren't doing that already with the TimeoutError itself is because Puppeteer has trouble with custom error classes. But a plain object shouldn't be an issue.

did you see my comments in #300 regarding node-fetch?

Yes. I think you're correct, that it is actually caused by an updated version of Chromium. I forgot that it was happening in the browser tests, which are a special case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your guidance. I've reworked the test. See what you think about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@sholladay Shall we try to close it this weekend?

test/browser.js Outdated Show resolved Hide resolved
@sholladay
Copy link
Collaborator

LGTM.

@ulken
Copy link
Contributor Author

ulken commented Nov 14, 2020

LGTM.

Cool beans 😎.

Just curious: what's stopping you from merging too? Only @sindresorhus who has authority to or do you have a convention that another maintainer should do the merge? Or something totally different 🙂.

@sindresorhus
Copy link
Owner

Just curious: what's stopping you from merging too? Only @sindresorhus who has authority to or do you have a convention that another maintainer should do the merge? Or something totally different 🙂.

@sholladay is free to merge, but sometimes a maintainer might want another maintainer to also take a look.

@sindresorhus sindresorhus changed the title Expose TimeoutError.request Expose TimeoutError#request Nov 14, 2020
@sindresorhus sindresorhus merged commit 599a45b into sindresorhus:master Nov 14, 2020
@sholladay
Copy link
Collaborator

I usually like to give some time between approving the final changes and merging them, to give other people a last chance to comment. Especially when I'm helping maintain a project that I was invited to, it's just common courtesy.

@ulken
Copy link
Contributor Author

ulken commented Nov 15, 2020

Alright, thanks for clarifying, guys! Great work 👍.

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.

TypeScript: the type for ky.TimeoutError does not expose request
3 participants