From d1ac5dd29b96cadf6f7cc2f87621cf5292375881 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 9 Jun 2016 09:44:49 -0700 Subject: [PATCH 1/3] Add specs for manifest.json read/parse error --- spec/api-browser-window-spec.js | 12 ++++++++++++ .../devtools-extensions/bad-manifest/manifest.json | 1 + 2 files changed, 13 insertions(+) create mode 100644 spec/fixtures/devtools-extensions/bad-manifest/manifest.json diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index bad3b80a9b5c..628829f24deb 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 000000000000..5c34318c2147 --- /dev/null +++ b/spec/fixtures/devtools-extensions/bad-manifest/manifest.json @@ -0,0 +1 @@ +} From f46edd5186b32987492b920d8e93001515712df9 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 9 Jun 2016 09:45:02 -0700 Subject: [PATCH 2/3] Throw errors reading/parsing manifest.json --- lib/browser/chrome-extension.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index fc49f5e06be5..69c1d0a566d3 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]) { From 6d3fc611bd908170c93482853d6f48dc3cfb5ac2 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 9 Jun 2016 10:08:21 -0700 Subject: [PATCH 3/3] Tweak duplicate extension message --- lib/browser/chrome-extension.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/browser/chrome-extension.js b/lib/browser/chrome-extension.js index 69c1d0a566d3..e3542e1cfa0b 100644 --- a/lib/browser/chrome-extension.js +++ b/lib/browser/chrome-extension.js @@ -57,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.`) } }