diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 97bf292f9e2..ea9dc15f2c7 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -22,12 +22,22 @@ const generateExtensionIdFromName = function (name) { // Create or get manifest object from |srcDirectory|. const getManifestFromPath = function (srcDirectory) { let manifest + let manifestContent try { - manifest = JSON.parse(fs.readFileSync(path.join(srcDirectory, 'manifest.json'))) - } catch (err) { - console.warn(`Attempted to load extension from ${srcDirectory}, but parsing the manifest failed.`) - console.warn('Error encountered:', err) + manifestContent = fs.readFileSync(path.join(srcDirectory, 'manifest.json')) + } catch (readError) { + console.warn(`Reading ${path.join(srcDirectory, 'manifest.json')} failed.`) + console.warn(readError.stack || readError) + throw readError + } + + try { + manifest = JSON.parse(manifestContent) + } catch (parseError) { + console.warn(`Parsing ${path.join(srcDirectory, 'manifest.json')} failed.`) + console.warn(parseError.stack || parseError) + throw parseError } if (!manifestNameMap[manifest.name]) { @@ -47,7 +57,7 @@ const getManifestFromPath = function (srcDirectory) { }) return manifest } else if (manifest && manifest.name) { - console.warn(`Attempted to load extension "${manifest.name}", but extension was already loaded!`) + console.warn(`Attempted to load extension "${manifest.name}" that has already been loaded.`) } } diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index cf3442d59ce..a5a1478d690 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -858,6 +858,18 @@ describe('browser-window module', function () { w.loadURL('about:blank') }) + it('throws errors for missing manifest.json files', function () { + assert.throws(function () { + BrowserWindow.addDevToolsExtension(path.join(__dirname, 'does-not-exist')) + }, /ENOENT: no such file or directory/) + }) + + it('throws errors for invalid manifest.json files', function () { + assert.throws(function () { + BrowserWindow.addDevToolsExtension(path.join(__dirname, 'fixtures', 'devtools-extensions', 'bad-manifest')) + }, /Unexpected token }/) + }) + describe('when the devtools is docked', function () { it('creates the extension', function (done) { w.webContents.openDevTools({mode: 'bottom'}) diff --git a/spec/fixtures/devtools-extensions/bad-manifest/manifest.json b/spec/fixtures/devtools-extensions/bad-manifest/manifest.json new file mode 100644 index 00000000000..5c34318c214 --- /dev/null +++ b/spec/fixtures/devtools-extensions/bad-manifest/manifest.json @@ -0,0 +1 @@ +}