Skip to content

Commit b9e10bc

Browse files
committed
fix: stop spinner before error propagates, show PM2 logs on health check failure
- Stop spinner explicitly on deploy error so ui.error output is visible - Add 2s delay between health check retries - Fetch last 30 lines of PM2 logs when health check fails so the user can see why the app didn't start without running a separate command
1 parent 4f3ad1e commit b9e10bc

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

src/cli/commands/deploy.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ export async function cmdDeploy(cwd: string, options: { dryRun?: boolean; skipBu
2222
spin.start(`Deploying ${chalk.bold(config.pm2?.name ?? config.app)}${config.ssh.user}@${config.ssh.host}`);
2323

2424
const deployer = new DeployService(executor, config, cwd);
25-
await deployer.execute(options.skipBuild ?? false);
25+
try {
26+
await deployer.execute(options.skipBuild ?? false);
27+
} catch (err) {
28+
spin.stop('Deploy failed');
29+
throw err;
30+
}
2631

2732
spin.stop(`Deployed ${chalk.bold(config.pm2?.name ?? config.app)}`);
2833

src/services/health.service.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,26 @@ export class HealthCheckService {
3838
if (lastStatus >= 200 && lastStatus < 400) {
3939
return { attempts: attempt, responseMs: lastResponseMs };
4040
}
41+
42+
if (attempt < retries) {
43+
await this.sleep(2000);
44+
}
45+
}
46+
47+
// Fetch PM2 logs to help diagnose why the app didn't start
48+
let diagnostics = '';
49+
if (this.config.pm2?.name) {
50+
const nodeVersion = this.config.nodeVersion === 'lts' ? '24' : this.config.nodeVersion;
51+
const mise = `export PATH="$HOME/.local/bin:$HOME/.local/share/mise/shims:$PATH"`;
52+
const logResult = await this.executor.exec(
53+
`${mise}; mise exec node@${nodeVersion} -- pm2 logs ${this.config.pm2.name} --lines 30 --nostream 2>&1 || true`,
54+
).catch(() => ({ stdout: '', stderr: '' }));
55+
const logs = logResult.stdout.trim();
56+
if (logs) diagnostics = `\n\nPM2 logs (last 30 lines):\n${logs}`;
4157
}
4258

4359
throw new HealthCheckError(
44-
`Health check failed after ${retries} attempts. Last status: ${lastStatus}`,
60+
`Health check failed after ${retries} attempts. Last status: ${lastStatus}` + diagnostics,
4561
retries,
4662
lastStatus,
4763
);

0 commit comments

Comments
 (0)