Skip to content
This repository was archived by the owner on Jul 13, 2020. It is now read-only.

More informative load errors #404

Closed
wants to merge 11 commits into from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ bower_components
tmp
coverage
.DS_Store
*.sw?
29 changes: 25 additions & 4 deletions src/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -516,14 +516,35 @@ function logloads(loads) {

// 15.2.5.2.4
function linkSetFailed(linkSet, load, exc) {
function requestsForLoad() {
var reqs = [];
linkSet.loads.forEach(function(aLoad){
Copy link
Member

Choose a reason for hiding this comment

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

Space after (aLoad)

aLoad.dependencies.forEach(function(dep){
if (dep.value == load.name) {
reqs.push({as: dep.key, from: aLoad.name});
}
});
});
return reqs;
}

var loader = linkSet.loader;
var requests;

if (load) {
if (load && linkSet.loads[0].name != load.name)
exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name);

if (load)
if (linkSet.loads[0].name != load.name) {
requests = requestsForLoad();

if (requests[0]) {
var req = requests[0];
exc = addToError(exc, 'Error loading ' + load.name + ' as "' + req.as + '" from ' + req.from);
} else {
exc = addToError(exc, 'Error loading ' + load.name + ' from ' + linkSet.loads[0].name);
Copy link
Member

Choose a reason for hiding this comment

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

This should have braces if the first group has braces.

}
}
else {
exc = addToError(exc, 'Error loading ' + load.name);
}
}
else {
exc = addToError(exc, 'Error linking ' + linkSet.loads[0].name);
Expand Down
8 changes: 4 additions & 4 deletions src/system-fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
fulfill(xhr.responseText);
}
function error() {
reject(xhr.statusText + ': ' + url || 'XHR error');
reject(new Error(xhr.statusText + ': ' + url || 'XHR error'));
}

xhr.onreadystatechange = function () {
Expand Down Expand Up @@ -68,9 +68,9 @@
else
url = url.substr(7);
return fs.readFile(url, function(err, data) {
if (err)
if (err) {
return reject(err);
else {
} else {
// Strip Byte Order Mark out if it's the leading char
var dataString = data + '';
if (dataString[0] === '\ufeff')
Expand All @@ -89,4 +89,4 @@
return new Promise(function(resolve, reject) {
fetchTextFromURL(load.address, resolve, reject);
});
};
};
1 change: 1 addition & 0 deletions test/loads/indirect-load.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './load-non-existent.js';
1 change: 1 addition & 0 deletions test/loads/noent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { nothing } from 'nosuchfile.js';