From 67c88d2f8a95043f8b504454fba7d3f5bc504511 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:33:55 -0700 Subject: [PATCH 01/10] Move Module require to top --- default_app/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/default_app/main.js b/default_app/main.js index e9b744c603ff..7c3b6b960609 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -1,6 +1,7 @@ const {app, dialog, shell, Menu} = require('electron') const fs = require('fs') +const Module = require('module') const path = require('path') const repl = require('repl') const url = require('url') @@ -222,7 +223,7 @@ app.once('ready', () => { }) if (option.modules.length > 0) { - require('module')._preloadModules(option.modules) + Module._preloadModules(option.modules) } function loadApplicationPackage (packagePath) { @@ -252,7 +253,7 @@ function loadApplicationPackage (packagePath) { app.setPath('userCache', path.join(app.getPath('cache'), app.getName())) app.setAppPath(packagePath) } - const Module = require('module') + try { Module._resolveFilename(packagePath, module, true) } catch (e) { From f691a46d4dc6f754227d7f419905af9d132b6c38 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:37:52 -0700 Subject: [PATCH 02/10] Use dialog.showErrorBox --- default_app/main.js | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/default_app/main.js b/default_app/main.js index 7c3b6b960609..e60c7d2615c4 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -275,15 +275,7 @@ function loadApplicationPackage (packagePath) { function showErrorMessage (message) { app.focus() - dialog.showMessageBox({ - message: 'Error opening app', - detail: message, - buttons: ['OK', 'Learn More'] - }, (response) => { - if (response === 1) { - shell.openExternal('http://electron.atom.io/docs') - } - }) + dialog.showErrorBox('Error launching app', message) process.exit(1) } From deb15e60b578e1576b1e6538f1e0a3e6355d3baf Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:38:04 -0700 Subject: [PATCH 03/10] Lead with package.json path --- default_app/main.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/default_app/main.js b/default_app/main.js index e60c7d2615c4..98fab26d2fd3 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -239,8 +239,8 @@ function loadApplicationPackage (packagePath) { try { packageJson = JSON.parse(fs.readFileSync(packageJsonPath)) } catch (e) { - showErrorMessage('Unable to parse package.json.\n\n' + - `${e.toString()} in ${packageJsonPath}`) + showErrorMessage(`Unable to parse ${packageJsonPath}\n\n${e.message}`) + return } if (packageJson.version) app.setVersion(packageJson.version) From 6de4249af8dc008daccb288bdddbeb23c2602b40 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:41:31 -0700 Subject: [PATCH 04/10] Tweak resolve filename error message --- default_app/main.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/default_app/main.js b/default_app/main.js index 98fab26d2fd3..32461525aa4e 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -257,9 +257,10 @@ function loadApplicationPackage (packagePath) { try { Module._resolveFilename(packagePath, module, true) } catch (e) { - showErrorMessage('Unable to find Electron app.\n\n' + - `See: ${packagePath}`) + showErrorMessage(`Unable to find Electron app at ${packagePath}.\n\n${e.message}`) + return } + // Run the app. Module._load(packagePath, module, true) } catch (e) { From 4a352063026fde28eed48075a6e8119cca1049a0 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:42:31 -0700 Subject: [PATCH 05/10] :art: --- default_app/main.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/default_app/main.js b/default_app/main.js index 32461525aa4e..8fc9792fec49 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -242,8 +242,10 @@ function loadApplicationPackage (packagePath) { showErrorMessage(`Unable to parse ${packageJsonPath}\n\n${e.message}`) return } - if (packageJson.version) app.setVersion(packageJson.version) + if (packageJson.version) { + app.setVersion(packageJson.version) + } if (packageJson.productName) { app.setName(packageJson.productName) } else if (packageJson.name) { From 63b84923ce5a8739363a4d2ea6e1d0d8b5d82acc Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:43:25 -0700 Subject: [PATCH 06/10] Update copy --- default_app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default_app/main.js b/default_app/main.js index 8fc9792fec49..02f7a9fdd001 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -309,7 +309,7 @@ if (option.file && !option.webdriver) { console.log('v' + process.versions.electron) process.exit(0) } else if (option.help) { - const helpMessage = `Electron v${process.versions.electron} - Cross Platform Desktop Application Shell + const helpMessage = `Electron ${process.versions.electron} - Build cross platform desktop apps with JavaScript, HTML, and CSS Usage: electron [options] [path] From 48522d4b70e4872184319cfe4e9197d01ced788f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:45:32 -0700 Subject: [PATCH 07/10] Remove custom MODULE_NOT_FOUND code check --- default_app/main.js | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/default_app/main.js b/default_app/main.js index 02f7a9fdd001..e90c4667fb6b 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -266,13 +266,9 @@ function loadApplicationPackage (packagePath) { // Run the app. Module._load(packagePath, module, true) } catch (e) { - if (e.code === 'MODULE_NOT_FOUND') { - showErrorMessage('Unable to open Electron app.\n\n' + - `${e.toString()}`) - } else { - console.error('App threw an error when running', e) - throw e - } + console.error('App threw an error during load') + console.error(e) + throw e } } From 74cde4e714eea16a30cd32ca5e77c69a9b4e8210 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:51:09 -0700 Subject: [PATCH 08/10] Log stack when available --- default_app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default_app/main.js b/default_app/main.js index e90c4667fb6b..58507c6900ea 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -267,7 +267,7 @@ function loadApplicationPackage (packagePath) { Module._load(packagePath, module, true) } catch (e) { console.error('App threw an error during load') - console.error(e) + console.error(e.stack || e) throw e } } From ca72d4346b69d4f3fe04c5d1c39f1e30b05b492f Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:53:23 -0700 Subject: [PATCH 09/10] application -> app for consitency --- default_app/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/default_app/main.js b/default_app/main.js index 58507c6900ea..3cc1f4268640 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -309,8 +309,7 @@ if (option.file && !option.webdriver) { Usage: electron [options] [path] - A path to an Electron application may be specified. - The path must be one of the following: + A path to an Electron app may be specified. The path must be one of the following: - index.js file. - Folder containing a package.json file. From 3e15021c125fe79b2a4d1c7ea695b588d0cab805 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Tue, 24 May 2016 09:56:36 -0700 Subject: [PATCH 10/10] Remove . after path to prevent confusion --- default_app/main.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/default_app/main.js b/default_app/main.js index 3cc1f4268640..e26c70590b1a 100644 --- a/default_app/main.js +++ b/default_app/main.js @@ -259,7 +259,7 @@ function loadApplicationPackage (packagePath) { try { Module._resolveFilename(packagePath, module, true) } catch (e) { - showErrorMessage(`Unable to find Electron app at ${packagePath}.\n\n${e.message}`) + showErrorMessage(`Unable to find Electron app at ${packagePath}\n\n${e.message}`) return }