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

Issue 808073 link

Starred by 3 users

Issue metadata

Status: Assigned
Owner:
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Feature



Sign in to add a comment

Additional context for failed import() statements

Project Member Reported by jeffy@chromium.org, Feb 1 2018

Issue description

Chrome Version: 64.0.3282.119 (Official Build) (64-bit)
OS: All


What steps will reproduce the problem?
Run code that will force a failure of an import() statement, like:

```
(async () => {
  try {
    const ignored = await import('does-not-exist.js');
  } catch (err) {
    console.dir(err);
  }
})();
```

This shows the string "Failed to resolve module specifier 'does-not-exist.js'" in the message and stack properties, but there's no context provided about why the request failed.


What is the expected result?
While the current result adheres to the spec, there's context information that would be useful.

As per Mathias:

> I just checked the import() spec and it doesn’t specify anything about what the exception should contain or what its message should be. So it’s up to the embedders.

Given that it's up to the embedders to include additional information if appropriate, I'd like to request that an additional property be added to the error that's raised. It would expose *why* the import() failed. The two scenarios that I'm looking to differentiate are whether the failure was due to a HTTP error response (like a 404, in the example provided) or due to a network failure.

This context can help a developer determine how they'd like to recover from the failure. For instance, if the failure is due to a HTTP 404, the developer might assume that they're trying to load a versioned asset that has since been updated, and if the failure is due to a network error, they'd realize that the failure was potentially recoverable once the network is more stable.


What happens instead?
The information that's exposed in the error does not give any context about why the import() failed.
 
Components: -Blink>JavaScript>API Blink>HTML>Modules
Owner: kouhei@chromium.org
Status: Assigned (was: Untriaged)
I agree this would be useful. Kouhei, can you ptal?
Adding an additional property would be a spec violation.

In the past we've not exposed these sort of things as it's a security issue. Maybe if all the CORS headers were set right we could e.g. expose the status code, but that would require some cross-browser discussion.

I'd encourage developers not to distinguish these cases anyway; it's not generally reliable. E.g. proxies can generate 404s in response to unstable network conditions; network errors are also returned for a variety of other reasons such as CORS failures; etc.

Sign in to add a comment