Skip to content

Commit 2e41028

Browse files
better handled errors
1 parent 12be9ae commit 2e41028

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

bin/create-webextension

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,6 @@ if (!process.argv[2]) {
99
process.exit(1);
1010
}
1111

12-
require("..").main(process.argv[2]);
12+
require("..").main(process.argv[2])
13+
.then(console.log)
14+
.catch(err => console.log(err.message));

index.js

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ function getProjectManifest(projectDirName) {
8787

8888
exports.main = function main(dirPath) {
8989
if (!dirPath) {
90-
throw new Error("Project directory name is a compulsory argument");
90+
throw new Error("Project directory name is a mandatory argument");
9191
}
9292

9393
const projectPath = path.resolve(dirPath);
@@ -106,16 +106,13 @@ exports.main = function main(dirPath) {
106106
.then(() => getProjectReadme(projectDirName))
107107
.then(projectReadme => fs.writeFile(path.join(projectPath, "README.md"),
108108
stripAnsi(projectReadme)))
109-
.then(() => getProjectCreatedMessage(projectPath))
110-
.then(console.log);
109+
.then(() => getProjectCreatedMessage(projectPath));
111110
}, error => {
112111
if (error.code === "EEXIST") {
113112
const msg = `Unable to create a new WebExtension: ${chalk.bold.underline(projectPath)} dir already exist.`;
114-
console.error(`${chalk.red(msg)}\n`);
115-
process.exit(1);
113+
throw new Error(msg);
116114
}
117115
}).catch((error) => {
118-
console.error(error);
119-
process.exit(1);
116+
throw error;
120117
});
121118
};

0 commit comments

Comments
 (0)