Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/playground/cli/src/blueprints-v2/worker-thread-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ async function mountResources(php: PHP, mounts: Mount[]) {
mount.vfsPath,
createNodeFsMountHandler(mount.hostPath)
);
} catch {
output.stderr(
`\x1b[31m\x1b[1mError mounting path ${mount.hostPath} at ${mount.vfsPath}\x1b[0m\n`
} catch (error) {
throw new Error(
`Error mounting path ${mount.hostPath} at ${mount.vfsPath}`,
Comment thread
gcsecsey marked this conversation as resolved.
Outdated
{ cause: error }
);
process.exit(1);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion packages/playground/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ function runCLI() {
// Dynamic import avoids loading run-cli when we're about to respawn.
// Do not await — top-level await is not supported in all environments.
import('./run-cli').then(({ parseOptionsAndRunCLI }) => {
parseOptionsAndRunCLI(args);
parseOptionsAndRunCLI(args).catch(() => {
process.exit(1);
});
});
Comment thread
brandonpayton marked this conversation as resolved.
}

Expand Down
12 changes: 6 additions & 6 deletions packages/playground/cli/src/run-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,15 +736,13 @@ export async function parseOptionsAndRunCLI(argsToParse: string[]) {
currentError = currentError.cause as Error;
} while (currentError instanceof Error);
console.error(
'\x1b[1m' +
messageChain.join(' caused by: ') +
'\x1b[0m'
'\x1b[1m' + messageChain.join(' caused by: ') + '\x1b[0m'
);
}
} else {
console.error('\x1b[1m' + describeError(e) + '\x1b[0m');
}
process.exit(1);
throw e;
Comment thread
gcsecsey marked this conversation as resolved.
}
}

Expand Down Expand Up @@ -1675,7 +1673,7 @@ export async function runCLI(args: RunCLIArgs): Promise<RunCLIServer | void> {
},
}).catch((error) => {
cliOutput.printError(describeError(error));
process.exit(1);
throw error;
Comment thread
gcsecsey marked this conversation as resolved.
Outdated
});

if (server && args.command === 'start' && !args.skipBrowser) {
Expand Down Expand Up @@ -1777,7 +1775,9 @@ function expandStartCommandArgs(
console.log(
`You may still remove the site's directory manually if you wish.`
);
process.exit(1);
throw new Error(
'This site is not managed by Playground CLI and cannot be reset.'
);
}
}

Expand Down
32 changes: 7 additions & 25 deletions packages/playground/cli/tests/run-cli.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,10 +339,7 @@ describe.each(blueprintVersions)(

const mounts = [];
for (let i = 0; i < 5; i++) {
const hostSubDir = path.join(
hostTmpDir,
`migration-${i}`
);
const hostSubDir = path.join(hostTmpDir, `migration-${i}`);
mkdirSync(hostSubDir, { recursive: true });
const hostFilePath = path.join(
hostSubDir,
Expand Down Expand Up @@ -1808,35 +1805,20 @@ describe('other run-cli behaviors', () => {

describe('port in use', () => {
test('should error when explicit port is already in use', async () => {
const stdoutMessages: string[] = [];
const mockStdout = vi
.spyOn(process.stdout, 'write')
.mockImplementation((chunk) => {
stdoutMessages.push(String(chunk));
return true;
});
const mockExit = vi
.spyOn(process, 'exit')
.mockImplementation(() => undefined as never);

const port = 12345;
const blockingServer = http.createServer();
await new Promise<void>((resolve) => {
blockingServer.listen(port, () => resolve());
});

try {
await runCLI({
command: 'server',
port,
});

expect(stdoutMessages.join('')).toContain(
`Error: listen EADDRINUSE: address already in use :::${port}`
);
await expect(
runCLI({
command: 'server',
port,
})
).rejects.toThrow(`EADDRINUSE`);
} finally {
mockExit.mockRestore();
mockStdout.mockRestore();
blockingServer.close();
}
});
Expand Down
Loading