Skip to content

Commit

Permalink
Add CliError
Browse files Browse the repository at this point in the history
  • Loading branch information
oligriffiths committed Mar 27, 2018
1 parent 499db17 commit 50a1a59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 11 additions & 6 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const fs = require('fs');
const WatchDetector = require('watch-detector');
const path = require('path');

const CliError = require('./errors/cli');
const broccoli = require('./index');
const messages = require('./messages');

Expand Down Expand Up @@ -40,8 +41,10 @@ module.exports = function broccoliCLI(args) {
try {
guardOutputDir(outputDir, options.overwrite);
} catch (e) {
console.error(e.message);
return process.exit(1);
if (e instanceof CliError) {
console.error(e.message);
return process.exit(1);
}
}
const outputTree = new TreeSync(builder.outputPath, outputDir);

Expand Down Expand Up @@ -81,8 +84,10 @@ module.exports = function broccoliCLI(args) {
try {
guardOutputDir(outputDir, options.overwrite);
} catch (e) {
console.error(e.message);
return process.exit(1);
if (e instanceof CliError) {
console.error(e.message);
return process.exit(1);
}
}

const builder = getBuilder(options);
Expand Down Expand Up @@ -171,13 +176,13 @@ function guardOutputDir(outputDir, overwrite) {
if (fs.existsSync(outputDir)) {
if (overwrite) {
if (isParentDirectory(outputDir)) {
throw new Error(
throw new CliError(
'option --overwrite can not be used if outputPath is a parent directory: ' + outputDir
);
}
return;
}
throw new Error(
throw new CliError(
outputDir +
'/ already exists; we cannot build into an existing directory, ' +
'pass --overwrite to overwrite the output directory'
Expand Down
4 changes: 4 additions & 0 deletions lib/errors/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
'use strict';

// Base class for cli errors
module.exports = class CliError extends Error {};

0 comments on commit 50a1a59

Please sign in to comment.