From 37146d79b4dd1e977155c63447893ba17ce2c3d0 Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Mon, 2 Nov 2015 18:33:49 -0800 Subject: [PATCH] Better error & retry tracking in Kitematic Signed-off-by: Jeffrey Morgan --- src/utils/DockerMachineUtil.js | 15 +++++++++++++ src/utils/SetupUtil.js | 41 ++++++++++++++++++++++++++-------- src/utils/VirtualBoxUtil.js | 4 +++- 3 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/utils/DockerMachineUtil.js b/src/utils/DockerMachineUtil.js index e342e7fce9..3f6802a53c 100644 --- a/src/utils/DockerMachineUtil.js +++ b/src/utils/DockerMachineUtil.js @@ -21,6 +21,21 @@ var DockerMachine = { } return fs.existsSync(this.command()); }, + version: function () { + return util.exec([this.command(), '-v']).then(stdout => { + try { + let tokens = stdout.split(' '); + if (tokens.length < 3) { + return Promise.resolve(null); + } + return Promise.resolve(tokens[2]); + } catch (err) { + return Promise.resolve(null); + } + }).catch(() => { + return Promise.resolve(null); + }); + }, isoversion: function (machineName = this.name()) { try { var data = fs.readFileSync(path.join(util.home(), '.docker', 'machine', 'machines', machineName, 'boot2docker.iso'), 'utf8'); diff --git a/src/utils/SetupUtil.js b/src/utils/SetupUtil.js index 25cdd8aafc..d5331c8869 100644 --- a/src/utils/SetupUtil.js +++ b/src/utils/SetupUtil.js @@ -32,6 +32,10 @@ export default { }, retry (removeVM) { + metrics.track('Retried Setup', { + removeVM + }); + router.get().transitionTo('loading'); if (removeVM) { machine.rm().finally(() => { @@ -48,18 +52,31 @@ export default { }, async setup () { - metrics.track('Started Setup'); + let virtualBoxVersion = await virtualBox.version(); + let machineVersion = await machine.version(); + + metrics.track('Started Setup', { + virtualBoxVersion, + machineVersion + }); + while (true) { try { setupServerActions.started({started: false}); - if (!virtualBox.installed()) { - router.get().transitionTo('setup'); - throw new Error('VirtualBox is not installed. Please install it via the Docker Toolbox.'); - } - if (!machine.installed()) { + // Make sure virtulBox and docker-machine are installed + let virtualBoxInstalled = virtualBox.installed(); + let machineInstalled = machine.installed(); + if (!virtualBoxInstalled || !machineInstalled) { router.get().transitionTo('setup'); - throw new Error('Docker Machine is not installed. Please install it via the Docker Toolbox.'); + if (!virtualBoxInstalled) { + setupServerActions.error({error: 'VirtualBox is not installed. Please install it via the Docker Toolbox.'}); + } else { + setupServerActions.error({error: 'Docker Machine is not installed. Please install it via the Docker Toolbox.'}); + } + this.clearTimers(); + await this.pause(); + continue; } setupServerActions.started({started: true}); @@ -106,7 +123,10 @@ export default { break; } catch (error) { router.get().transitionTo('setup'); - metrics.track('Setup Failed'); + metrics.track('Setup Failed', { + virtualBoxVersion, + machineVersion + }); setupServerActions.error({error}); bugsnag.notify('SetupError', error.message, { error: error, @@ -116,6 +136,9 @@ export default { await this.pause(); } } - metrics.track('Setup Finished'); + metrics.track('Setup Finished', { + virtualBoxVersion, + machineVersion + }); } }; diff --git a/src/utils/VirtualBoxUtil.js b/src/utils/VirtualBoxUtil.js index 28ba6a5f4d..4906344eac 100644 --- a/src/utils/VirtualBoxUtil.js +++ b/src/utils/VirtualBoxUtil.js @@ -34,7 +34,9 @@ var VirtualBox = { reject('VBoxManage -v output format not recognized.'); } resolve(match[1]); - }).catch(reject); + }).catch(() => { + resolve(null); + }); }); }, poweroffall: function () {