Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions src/extension-support/extension-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,12 +491,7 @@ class ExtensionManager {
}

_failedLoadingExtensionScript (error) {
// Don't set the current extension counter to 0, otherwise it will go negative if another
// extension finishes or fails to load.
this.loadingAsyncExtensions--;
this.asyncExtensionsLoadedCallbacks.forEach(i => i.reject(error));
this.asyncExtensionsLoadedCallbacks = [];
// Re-throw error so the promise still rejects.
this._finishedLoadingExtensionScript();
throw error;
}

Expand Down
5 changes: 4 additions & 1 deletion src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,10 @@ class VirtualMachine extends EventEmitter {
throw new Error(`Unknown extension: ${extensionID}`);
}
if (await this.securityManager.canLoadExtensionFromProject(url)) {
extensionPromises.push(this.extensionManager.loadExtensionURL(url));
extensionPromises.push(this.extensionManager.loadExtensionURL(url).catch(error => {
log.error(`Could not load extension ${extensionID} from ${url}`, error);
this.emit('EXTENSION_LOAD_ERROR', {extensionID, url, error});
}));
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions test/integration/tw_security_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,40 @@ test('Allow both extensions', async t => {
t.end();
});

test('Extension that fails to load does not stop the project', async t => {
const vm = new VirtualMachine();
const loadErrors = [];
vm.on('EXTENSION_LOAD_ERROR', data => loadErrors.push(data));
vm.extensionManager.loadExtensionURL = url => {
if (url === FETCH_EXTENSION) {
return Promise.reject(new Error('Error: Uncaught Error: This extension must run unsandboxed.'));
}
return Promise.resolve();
};
vm.securityManager.canLoadExtensionFromProject = () => true;
await vm.loadProject(testProject);
t.equal(vm.runtime.targets.length, 2);
t.equal(loadErrors.length, 1);
t.equal(loadErrors[0].url, FETCH_EXTENSION);
t.equal(loadErrors[0].extensionID, 'fetch');
t.end();
});

test('Extension that fails while the next prompt is open is not an unhandled rejection', async t => {
const vm = new VirtualMachine();
const unhandled = [];
const onUnhandled = reason => unhandled.push(reason);
process.on('unhandledRejection', onUnhandled);
vm.extensionManager.loadExtensionURL = () => Promise.reject(new Error('load failed'));
vm.securityManager.canLoadExtensionFromProject = () => new Promise(resolve => setTimeout(() => resolve(true), 10));
await vm.loadProject(testProject);
await new Promise(resolve => setTimeout(resolve, 10));
process.off('unhandledRejection', onUnhandled);
t.same(unhandled, []);
t.equal(vm.runtime.targets.length, 2);
t.end();
});

test('canFetch', async t => {
const vm = new VirtualMachine();
setupUnsandboxedExtensionAPI(vm);
Expand Down
12 changes: 12 additions & 0 deletions test/unit/tw_extension_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,15 @@ test('dynamic extension menus tolerate missing methods and empty results', t =>
vm.quit();
t.end();
});

test('a failed extension load does not reject other loads waiting for extensions', async t => {
const manager = new ExtensionManager({});
manager.loadingAsyncExtensions = 2;
const waiting = manager.allAsyncExtensionsLoaded();
t.throws(() => manager._failedLoadingExtensionScript(new Error('failed')), /failed/);
t.equal(manager.loadingAsyncExtensions, 1);
manager._finishedLoadingExtensionScript();
await waiting;
t.equal(manager.loadingAsyncExtensions, 0);
t.end();
});
Loading