Skip to content

Commit

Permalink
fix(create-twilio-function): handle rimraf failing (#400)
Browse files Browse the repository at this point in the history
Received a report that creating a new project had failed for a developer
and then the cleanup task didn't end. There was an issue with deleting
the files that had been created which threw an unhandled error in the
cleanUpAndExit function leading to the spinner never stopping.

This adds a try/catch/finally around rimraf in cleanUpAndExit to ensure
that it does indeed exit.
  • Loading branch information
philnash authored Aug 26, 2022
1 parent e95e726 commit b15a1cb
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions packages/create-twilio-function/src/create-twilio-function.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,16 @@ const successMessage = require('./create-twilio-function/success-message');
async function cleanUpAndExit(projectDir, spinner, errorMessage) {
spinner.fail(errorMessage);
spinner.start('Cleaning up project directories and files');
await rimraf(projectDir);
spinner.stop().clear();
process.exitCode = 1;
try {
await rimraf(projectDir);
} catch (error) {
spinner.fail(
`There was an error cleaning up the project. Some files may still be present in ${projectDir}`
);
} finally {
spinner.stop().clear();
process.exitCode = 1;
}
}

async function performTaskWithSpinner(spinner, message, task) {
Expand Down

0 comments on commit b15a1cb

Please sign in to comment.