Skip to content

Commit

Permalink
Merge pull request snyk#214 from snyk/fix/clear-spinner-on-errors
Browse files Browse the repository at this point in the history
fix: clear spinner labels on errors
  • Loading branch information
adrukh committed Sep 9, 2018
2 parents f650729 + 6f0f37f commit fb1d018
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 21 deletions.
10 changes: 8 additions & 2 deletions cli/commands/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,14 @@ function githubAuth(via) {
}, 2000);
// start checking the token immediately in case they've already
// opened the url manually
return testAuthComplete(token).then(spinner.clear(lbl));
});
return testAuthComplete(token);
})
// clear spinnger in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
}

function testAuthComplete(token) {
Expand Down
10 changes: 10 additions & 0 deletions cli/commands/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ function monitor() {
.then(function () {
return moduleInfo.inspect(path, targetFile, options);
})
// clear spinner in case of success or failure
.then(spinner.clear(analyzingDepsSpinnerLabel))
.catch(function (error) {
spinner.clear(analyzingDepsSpinnerLabel)();
throw error;
})
.then(function (info) {
return spinner(postingMonitorSpinnerLabel)
.then(function () {
Expand All @@ -90,7 +95,12 @@ function monitor() {
};
return snyk.monitor(path, meta, info);
})
// clear spinner in case of success or failure
.then(spinner.clear(postingMonitorSpinnerLabel))
.catch(function (error) {
spinner.clear(postingMonitorSpinnerLabel)();
throw error;
})
.then(function (res) {
res.path = path;
var endpoint = url.parse(config.API);
Expand Down
21 changes: 18 additions & 3 deletions cli/commands/protect/wizard.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,12 @@ function processAnswers(answers, policy, options) {
options.packageTrailing;
return spinner(lbl)
.then(fs.writeFile(packageFile, packageString))
.then(spinner.clear(lbl));
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
}
})
.then(function () {
Expand All @@ -479,7 +484,12 @@ function processAnswers(answers, policy, options) {
var lbl = 'Updating npm-shrinkwrap.json...';
return spinner(lbl)
.then(npm.bind(null, 'shrinkwrap', null, live, cwd, null))
.then(spinner.clear(lbl));
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
}
})
.then(function () {
Expand All @@ -501,7 +511,12 @@ function processAnswers(answers, policy, options) {
return info.inspect(cwd, targetFile, options)
.then(spinner(lbl))
.then(snyk.monitor.bind(null, cwd, meta))
.then(spinner.clear(lbl));
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
})
.then(function (monitorRes) {
var endpoint = url.parse(config.API);
Expand Down
8 changes: 7 additions & 1 deletion cli/commands/unpublished/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ module.exports = function (cwd) {
'shed-packages/\n');
});
});
}).then(spinner.clear(lbl));
})
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
};
25 changes: 16 additions & 9 deletions lib/protect/patch.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,23 @@ function patch(vulns, live, cwd) {
});

return promise;
}).then(spinner.clear(lbl)).then(function (res) {
if (errorList.length) {
errorList.forEach(function (error) {
console.log(chalk.red(errors.message(error)));
});
throw new Error('Please email support@snyk.io if this problem persists.');
}
})
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
})
.then(function (res) {
if (errorList.length) {
errorList.forEach(function (error) {
console.log(chalk.red(errors.message(error)));
});
throw new Error('Please email support@snyk.io if this problem persists.');
}

return res;
});
return res;
});
}

function patchRule(vuln) {
Expand Down
5 changes: 5 additions & 0 deletions lib/protect/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ function update(packages, live, pkgManager) {
});
return promise;
})
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
})
.then(function (res) {
if (error) {
console.error(chalk.red(errors.message(error)));
Expand Down
25 changes: 20 additions & 5 deletions lib/snyk-test/npm/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ function generateDependenciesFromLockfile(root, options) {
.then(function () {
return lockFileParser.buildDepTree(manifestFile, lockFile, options.dev);
})
.then(
spinner.clear(resolveModuleSpinnerLabel)
);
// clear spinner in case of success or failure
.then(spinner.clear(resolveModuleSpinnerLabel))
.catch(function (error) {
spinner.clear(resolveModuleSpinnerLabel)();
throw error;
});
}

function getDependenciesFromNodeModules(root, options) {
Expand All @@ -163,7 +166,13 @@ function getDependenciesFromNodeModules(root, options) {
.then(function () {
return snyk.modules(
root, Object.assign({}, options, {noFromArrays: true}));
}).then(spinner.clear(resolveModuleSpinnerLabel));
})
// clear spinner in case of success or failure
.then(spinner.clear(resolveModuleSpinnerLabel))
.catch(function (error) {
spinner.clear(resolveModuleSpinnerLabel)();
throw error;
});
});
}

Expand Down Expand Up @@ -263,7 +272,13 @@ function queryForVulns(data, modules, hasDevDependencies, root, options) {

return res;
});
}).then(spinner.clear(lbl));
})
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
}

function pluckPolicies(pkg) {
Expand Down
13 changes: 12 additions & 1 deletion lib/snyk-test/run-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ function runTest(packageManager, root, options) {

return res;
});
}).then(spinner.clear(lbl));
})
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
});
});
}

Expand Down Expand Up @@ -123,7 +129,12 @@ function assembleLocalPayload(root, options, policyLocations) {
.then(function () {
return moduleInfo.inspect(root, options.file, options);
})
// clear spinner in case of success or failure
.then(spinner.clear(lbl))
.catch(function (error) {
spinner.clear(lbl)();
throw error;
})
.then(function (info) {
var pkg = info.package;
if (_.get(info, 'plugin.packageManager')) {
Expand Down

0 comments on commit fb1d018

Please sign in to comment.