Skip to content

Commit 6dfa8db

Browse files
fix: graceful recovery for failed spinner step
1 parent 69af9ec commit 6dfa8db

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

Diff for: src/shared/cli/spinners.ts

+17-16
Original file line numberDiff line numberDiff line change
@@ -40,32 +40,33 @@ export async function withSpinners(
4040
let currentLabel!: string;
4141
let lastLogged!: string;
4242

43-
try {
44-
for (const [label, run] of tasks) {
45-
currentLabel = label;
43+
for (const [label, run] of tasks) {
44+
currentLabel = label;
4645

47-
const line = makeLine(chalk.gray(` - ${label}`));
48-
const stopWriting = startLineWithDots(line);
46+
const line = makeLine(chalk.gray(` - ${label}`));
47+
const stopWriting = startLineWithDots(line);
4948

49+
try {
5050
await run();
51+
} catch (error) {
52+
const descriptor = `${lowerFirst(label)} > ${lowerFirst(currentLabel)}`;
5153

52-
const lineLength = stopWriting();
53-
lastLogged = chalk.gray(`${line} ✔️\n`);
54+
logLine(chalk.red(`❌ Error ${descriptor}.`));
5455

56+
throw new Error(`Failed ${descriptor}`, { cause: error });
57+
} finally {
58+
const lineLength = stopWriting();
5559
readline.clearLine(process.stdout, -1);
5660
readline.moveCursor(process.stdout, -lineLength, 0);
57-
process.stdout.write(lastLogged);
5861
}
5962

60-
readline.moveCursor(process.stdout, -lastLogged.length, -tasks.length - 2);
61-
readline.clearScreenDown(process.stdout);
63+
lastLogged = chalk.gray(`${line} ✔️\n`);
6264

63-
logNewSection(chalk.green(`✅ Passed ${lowerFirst(label)}.`));
64-
} catch (error) {
65-
const descriptor = `${lowerFirst(label)} > ${lowerFirst(currentLabel)}`;
65+
process.stdout.write(lastLogged);
66+
}
6667

67-
logLine(chalk.red(`❌ Error ${descriptor}.`));
68+
readline.moveCursor(process.stdout, -lastLogged.length, -tasks.length - 2);
69+
readline.clearScreenDown(process.stdout);
6870

69-
throw new Error(`Failed ${descriptor}`, { cause: error });
70-
}
71+
logNewSection(chalk.green(`✅ Passed ${lowerFirst(label)}.`));
7172
}

0 commit comments

Comments
 (0)