fix: failure handling

This commit is contained in:
cha0s 2024-02-10 00:11:13 -06:00
parent e6c2d49008
commit 855999b3a1
2 changed files with 16 additions and 7 deletions

View File

@ -33,13 +33,16 @@ const {
try { try {
await stat(destination); await stat(destination);
const error = new Error( const error = new Error(
`@flecks/create-app: destination '${destination} already exists: aborting`, `@flecks/create-app: destination '${destination}' already exists: aborting`,
); );
error.code = 129; error.code = 1;
throw error; throw error;
} }
// eslint-disable-next-line no-empty catch (error) {
catch (error) {} if ('ENOENT' !== error.code) {
throw error;
}
}
const fileTree = await move(name, join(__dirname, '..', 'template')); const fileTree = await move(name, join(__dirname, '..', 'template'));
fileTree.pipe( fileTree.pipe(
'build/flecks.yml', 'build/flecks.yml',
@ -50,12 +53,17 @@ const {
); );
// Write the tree. // Write the tree.
await fileTree.writeTo(destination); await fileTree.writeTo(destination);
await install({cwd: destination, packageManager}); if (0 !== await install({cwd: destination, packageManager})) {
await build({cwd: destination, packageManager}); throw new Error('installation failed');
}
if (0 !== await build({cwd: destination, packageManager})) {
throw new Error('build failed');
}
} }
catch (error) { catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error(error); console.error('creation failed:', error);
process.exitCode = 1;
} }
}); });
await program.parseAsync(process.argv); await program.parseAsync(process.argv);

View File

@ -92,6 +92,7 @@ const {
catch (error) { catch (error) {
// eslint-disable-next-line no-console // eslint-disable-next-line no-console
console.error('creation failed:', error); console.error('creation failed:', error);
process.exitCode = 1;
} }
}); });
await program.parseAsync(process.argv); await program.parseAsync(process.argv);