New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 602909 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: Apr 2016
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: All
Pri: 3
Type: Bug



Sign in to add a comment

spec compliance: fetch (and maybe others) should throw exceptions, not reject promises

Project Member Reported by mgiuca@chromium.org, Apr 13 2016

Issue description

Version: 52
OS: Linux

I'm just picking on the fetch API for ease-of-access but this looks like a more widespread spec compliance issue. Certain APIs are specced as "throw a <Exception>" but appear to be implemented as "reject <promise> with a <Exception>". I could be misinterpreting the spec. Both Chrome and Firefox exhibit this non-spec-compliant behaviour.

What steps will reproduce the problem?
fetch('http://%zz').then(x => console.log('success:', x), y => console.log('error:', y));

What is the expected output?
A TypeError is thrown.

What do you see instead?
Console:
error: TypeError: Failed to execute 'fetch' on 'Window': Failed to parse URL from http://%zz(…)

Additional info:
See https://fetch.spec.whatwg.org/#fetch-api §6.3 Request(input, init) constructor, Step 12.2:
"If parsedURL is failure, throw a TypeError."

It doesn't say to reject the promise, nor can I find anything in the Web IDL spec that says "throw an Exception" can be interpreted as "reject a promise".

More concerning, I found that TypeErrors generated automatically by the IDL bindings code in Chrome will reject the promise if there is a promise result. The Web IDL spec says to throw TypeErrors, not reject promises.

Could someone comment on whether this is an implementation bug, a spec problem, or whether I am just misinterpreting (if the latter, please point me to where the spec agrees with the implementation).
 
See https://fetch.spec.whatwg.org/#dom-global-fetch:

Let request be the associated request of the result of invoking the initial value of Request as constructor with input and init as arguments. If this throws an exception, reject p with it and return p.

FYI: Promise-returning functions should not throw an exception. See https://www.w3.org/2001/tag/doc/promises-guide#always-return-promises.

Comment 2 by mgiuca@chromium.org, Apr 13 2016

Status: WontFix (was: Assigned)
#1 Thanks, and that links to the Web IDL spec which also says this:
https://heycam.github.io/webidl/#es-operations

"If the operation has a return type that is a promise type, then: Let reject be the initial value of %Promise%.reject. Return the result of calling reject with %Promise% as the this object and the exception as the single argument value."

So that settles all of my concerns regarding this. It is *very* hard to figure this out though.

WAI

Sign in to add a comment