Skip to content

Commit a42c7f3

Browse files
authored
Fix undefined error handling (#146)
1 parent cfdfe20 commit a42c7f3

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

src/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ const translate = async (
389389
ncp(
390390
evaluateFilePath(workingDir, dirStructure, sourceLang),
391391
evaluateFilePath(resolvedCacheDir, dirStructure, sourceLang),
392-
(err) => (err ? rej() : res(null)),
392+
(err) => (err ? rej(err) : res(null)),
393393
),
394394
);
395395
console.log(chalk`└── {green.bold Translation files have been cached.}`);
@@ -441,11 +441,17 @@ translate(
441441
commander.appName,
442442
commander.context,
443443
commander.overwrite,
444-
).catch((e: Error) => {
444+
).catch((e: unknown) => {
445445
console.log();
446446
console.log(chalk.bgRed('An error has occurred:'));
447-
console.log(chalk.bgRed(e.message));
448-
console.log(chalk.bgRed(e.stack));
447+
if (e instanceof Error) {
448+
console.log(chalk.bgRed(e.message));
449+
if (e.stack) {
450+
console.log(chalk.bgRed(e.stack));
451+
}
452+
} else {
453+
console.log(chalk.bgRed(String(e)));
454+
}
449455
console.log();
450456
process.exit(1);
451457
});

0 commit comments

Comments
 (0)