Skip to content

Commit f17870b

Browse files
committed
use error marker instead of exit code
1 parent cb2ae26 commit f17870b

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

extensions/positron-dev-containers/src/container/terminalBuilder.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ export class TerminalBuilder {
178178
const scriptExt = isWindows ? '.ps1' : '.sh';
179179
const scriptPath = path.join(os.tmpdir(), `devcontainer-build-${timestamp}${scriptExt}`);
180180
const markerPath = path.join(os.tmpdir(), `devcontainer-build-${timestamp}.done`);
181+
const errorPath = path.join(os.tmpdir(), `devcontainer-build-${timestamp}.error`);
181182
const containerIdPath = path.join(os.tmpdir(), `devcontainer-build-${timestamp}.id`);
182183
const containerNamePath = path.join(os.tmpdir(), `devcontainer-build-${timestamp}.name`);
183184

@@ -193,7 +194,8 @@ export class TerminalBuilder {
193194
const generateShellScript = () => {
194195
let script = '#!/bin/sh\nset -e\n\n';
195196
script += '# Trap errors to keep terminal open so user can see what failed\n';
196-
script += 'trap \'echo ""; echo "==> ERROR: Build failed! Press Enter to close this terminal..."; read dummy\' ERR\n\n';
197+
script += '# Write error marker and exit 0 to avoid VS Code toast about exit code\n';
198+
script += `trap 'echo ""; echo "==> ERROR: Build failed! Press Enter to close this terminal..."; echo "failed" > "${errorPath}"; read dummy; exit 0' ERR\n\n`;
197199

198200
if (rebuild) {
199201
script += 'echo "==> Removing existing containers..."\n';
@@ -206,14 +208,16 @@ export class TerminalBuilder {
206208
const generatePowerShellScript = () => {
207209
let script = '$ErrorActionPreference = "Stop"\n\n';
208210
script += '# Trap errors to keep terminal open so user can see what failed\n';
211+
script += '# Write error marker and exit 0 to avoid VS Code toast about exit code\n';
209212
script += 'trap {\n';
210213
script += ' Write-Host ""\n';
211214
script += ' Write-Host "==> ERROR: Build failed!"\n';
212215
script += ' Write-Host "Error: $_" -ForegroundColor Red\n';
213216
script += ' Write-Host ""\n';
217+
script += ` "failed" | Out-File -FilePath "${errorPath}" -Encoding utf8\n`;
214218
script += ' Write-Host "Press Enter to close this terminal..."\n';
215219
script += ' Read-Host\n';
216-
script += ' exit 1\n';
220+
script += ' exit 0\n';
217221
script += '}\n\n';
218222

219223
if (rebuild) {
@@ -449,10 +453,21 @@ export class TerminalBuilder {
449453
const timeout = 10 * 60 * 1000; // 10 minutes
450454

451455
while (true) {
456+
// Check for success marker
452457
if (fs.existsSync(markerPath)) {
453458
break;
454459
}
455460

461+
// Check for error marker (build failed but exited cleanly)
462+
if (fs.existsSync(errorPath)) {
463+
// Clean up
464+
try {
465+
fs.unlinkSync(scriptPath);
466+
fs.unlinkSync(errorPath);
467+
} catch { }
468+
throw new Error('Container build failed. Check the terminal output for details.');
469+
}
470+
456471
if (Date.now() - startTime > timeout) {
457472
// Clean up
458473
try {
@@ -480,6 +495,7 @@ export class TerminalBuilder {
480495
try {
481496
fs.unlinkSync(scriptPath);
482497
fs.unlinkSync(markerPath);
498+
fs.unlinkSync(errorPath);
483499
fs.unlinkSync(containerIdPath);
484500
fs.unlinkSync(containerNamePath);
485501
} catch { }

0 commit comments

Comments
 (0)