From 7b7f1d38702952b46b1bf7b4e9c0135c9b36bcdb Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Mon, 2 Nov 2015 19:23:41 -0800 Subject: [PATCH] Better error reports around docker-machine Signed-off-by: Jeffrey Morgan --- src/menutemplate.js | 1 + src/utils/DockerMachineUtil.js | 18 +++++++++++++----- src/utils/SetupUtil.js | 32 +++++++++++++++++++++----------- src/utils/VirtualBoxUtil.js | 25 +++++++++---------------- src/utils/WebUtil.js | 3 --- 5 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/menutemplate.js b/src/menutemplate.js index 3322ec7d..5bc23a30 100644 --- a/src/menutemplate.js +++ b/src/menutemplate.js @@ -16,6 +16,7 @@ var MenuTemplate = function () { submenu: [ { label: 'About Kitematic', + enabled: !!docker.host, click: function () { metrics.track('Opened About', { from: 'menu' diff --git a/src/utils/DockerMachineUtil.js b/src/utils/DockerMachineUtil.js index 3f6802a5..4f8a8e3b 100644 --- a/src/utils/DockerMachineUtil.js +++ b/src/utils/DockerMachineUtil.js @@ -24,11 +24,11 @@ var DockerMachine = { version: function () { return util.exec([this.command(), '-v']).then(stdout => { try { - let tokens = stdout.split(' '); - if (tokens.length < 3) { - return Promise.resolve(null); + var match = stdout.match(/(\d+\.\d+\.\d+).*/); + if (!match || match.length < 2) { + Promise.reject('docker-machine -v output format not recognized.'); } - return Promise.resolve(tokens[2]); + return Promise.resolve(match[1]); } catch (err) { return Promise.resolve(null); } @@ -146,7 +146,7 @@ var DockerMachine = { util.exec('start powershell.exe ' + cmd, {env: { 'DOCKER_HOST': machineUrl, - 'DOCKER_CERT_PATH': path.join(util.home(), '.docker/machine/machines/' + machineName), + 'DOCKER_CERT_PATH': path.join(util.home(), '.docker', 'machine', 'machines', machineName), 'DOCKER_TLS_VERIFY': 1 } }); @@ -157,6 +157,14 @@ var DockerMachine = { util.exec([path.join(process.env.RESOURCES_PATH, 'terminal'), `DOCKER_HOST=${machineUrl} DOCKER_CERT_PATH=${path.join(util.home(), '.docker/machine/machines/' + machineName)} DOCKER_TLS_VERIFY=1 ${cmd}`]).then(() => {}); }); } + }, + virtualBoxLogs: function (machineName = this.name()) { + let logsPath = path.join(util.home(), '.docker', 'machine', 'machines', machineName, machineName, 'Logs', 'VBox.log'); + if (fs.existsSync(logsPath)) { + return fs.readFileSync(logsPath, 'utf8'); + } else { + return null; + } } }; diff --git a/src/utils/SetupUtil.js b/src/utils/SetupUtil.js index d5331c88..b0cf1ba0 100644 --- a/src/utils/SetupUtil.js +++ b/src/utils/SetupUtil.js @@ -52,14 +52,8 @@ export default { }, async setup () { - let virtualBoxVersion = await virtualBox.version(); - let machineVersion = await machine.version(); - - metrics.track('Started Setup', { - virtualBoxVersion, - machineVersion - }); - + let virtualBoxVersion = null; + let machineVersion = null; while (true) { try { setupServerActions.started({started: false}); @@ -79,7 +73,15 @@ export default { continue; } + virtualBoxVersion = await virtualBox.version(); + machineVersion = await machine.version(); + setupServerActions.started({started: true}); + metrics.track('Started Setup', { + virtualBoxVersion, + machineVersion + }); + let exists = await virtualBox.vmExists(machine.name()) && fs.existsSync(path.join(util.home(), '.docker', 'machine', 'machines', machine.name())); if (!exists) { router.get().transitionTo('setup'); @@ -128,10 +130,18 @@ export default { machineVersion }); setupServerActions.error({error}); - bugsnag.notify('SetupError', error.message, { - error: error, - output: error.message + + let message = error.message.split('\n'); + let lastLine = message.length > 1 ? message[message.length - 2] : 'Docker Machine encountered an error.'; + let virtualBoxLogs = machine.virtualBoxLogs(); + bugsnag.notify('Setup Failed', lastLine, { + 'Docker Machine Logs': error.message, + 'VirtualBox Logs': virtualBoxLogs, + 'VirtualBox Version': virtualBoxVersion, + 'Machine Version': machineVersion, + groupingHash: machineVersion }, 'info'); + this.clearTimers(); await this.pause(); } diff --git a/src/utils/VirtualBoxUtil.js b/src/utils/VirtualBoxUtil.js index 4906344e..2350da9e 100644 --- a/src/utils/VirtualBoxUtil.js +++ b/src/utils/VirtualBoxUtil.js @@ -16,27 +16,20 @@ var VirtualBox = { } }, installed: function () { - if (util.isWindows()) { - return (process.env.VBOX_MSI_INSTALL_PATH && fs.existsSync(path.join(process.env.VBOX_MSI_INSTALL_PATH, 'VBoxManage.exe'))) || - (process.env.VBOX_INSTALL_PATH && fs.existsSync(path.join(process.env.VBOX_INSTALL_PATH, 'VBoxManage.exe'))); - } else { - return fs.existsSync('/Applications/VirtualBox.app') && fs.existsSync('/Applications/VirtualBox.app/Contents/MacOS/VBoxManage'); - } + return fs.existsSync(this.command()); }, active: function () { return fs.existsSync('/dev/vboxnetctl'); }, version: function () { - return new Promise((resolve, reject) => { - util.exec([this.command(), '-v']).then(stdout => { - var match = stdout.match(/(\d+\.\d+\.\d+).*/); - if (!match || match.length < 2) { - reject('VBoxManage -v output format not recognized.'); - } - resolve(match[1]); - }).catch(() => { - resolve(null); - }); + return util.exec([this.command(), '-v']).then(stdout => { + var match = stdout.match(/(\d+\.\d+\.\d+).*/); + if (!match || match.length < 2) { + Promise.reject('VBoxManage -v output format not recognized.'); + } + return Promise.resolve(match[1]); + }).catch(() => { + return Promise.resolve(null); }); }, poweroffall: function () { diff --git a/src/utils/WebUtil.js b/src/utils/WebUtil.js index c146e0eb..8bc2f735 100644 --- a/src/utils/WebUtil.js +++ b/src/utils/WebUtil.js @@ -33,9 +33,6 @@ var WebUtil = { bugsnag.releaseStage = process.env.NODE_ENV === 'development' ? 'development' : 'production'; bugsnag.notifyReleaseStages = ['production']; bugsnag.appVersion = app.getVersion(); - bugsnag.metaData = { - beta: !!settingsjson.beta - }; bugsnag.beforeNotify = function(payload) { if (!metrics.enabled()) {