Skip to content

Commit 77fca8d

Browse files
committed
issue missing root cause of error #845 solution
1 parent f475b2b commit 77fca8d

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/spec-common/injectHeadless.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -503,18 +503,26 @@ async function runLifecycleCommand({ lifecycleHook }: ResolverParameters, contai
503503
// doesn't get interleaved with the output of other commands.
504504
const printMode = name ? 'off' : 'continuous';
505505
const env = { ...(await remoteEnv), ...(await secrets) };
506-
const { cmdOutput } = await runRemoteCommand({ ...lifecycleHook, output: infoOutput }, containerProperties, typeof postCommand === 'string' ? ['/bin/sh', '-c', postCommand] : postCommand, remoteCwd, { remoteEnv: env, pty: true, print: printMode });
507506

508-
// 'name' is set when parallel execution syntax is used.
509-
if (name) {
510-
infoOutput.raw(`\x1b[1mRunning ${name} from ${userCommandOrigin}...\x1b[0m\r\n${cmdOutput}\r\n`);
511-
}
507+
try {
508+
const { cmdOutput } = await runRemoteCommand({ ...lifecycleHook, output: infoOutput }, containerProperties, typeof postCommand === 'string' ? ['/bin/sh', '-c', postCommand] : postCommand, remoteCwd, { remoteEnv: env, pty: true, print: printMode });
512509

513-
infoOutput.event({
514-
type: 'progress',
515-
name: progressName,
516-
status: 'succeeded',
517-
});
510+
// 'name' is set when parallel execution syntax is used.
511+
if (name) {
512+
infoOutput.raw(`\x1b[1mRunning ${name} of ${lifecycleHookName} from ${userCommandOrigin}...\x1b[0m\r\n${cmdOutput}\r\n`);
513+
}
514+
} catch (err) {
515+
if (printMode === 'off' && err?.cmdOutput) {
516+
infoOutput.raw(`\r\n\x1b[1m${err.cmdOutput}\x1b[0m\r\n\r\n`);
517+
if (err?.code) {
518+
infoOutput.write(toErrorText(`${lifecycleHookName} failed with exit code ${err.code}. Skipping any further user-provided commands.`));
519+
}
520+
throw new ContainerError({
521+
description: `${name ? `${name} of ${lifecycleHookName}` : lifecycleHookName} from ${userCommandOrigin} failed.`,
522+
originalError: err
523+
});
524+
}
525+
}
518526
}
519527

520528
infoOutput.raw(`\x1b[1mRunning the ${lifecycleHookName} from ${userCommandOrigin}...\x1b[0m\r\n\r\n`);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Example devcontainer.json configuration,
2+
// wired into the vscode launch task (.vscode/launch.json)
3+
{
4+
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
5+
"features": {
6+
"ghcr.io/devcontainers/features/python:1": {
7+
"version": "latest",
8+
"installTools": "false"
9+
}
10+
},
11+
"postStartCommand": {
12+
"poetry setup": ["/bin/bash", "-i", "-c", "python3 -m venv $HOME/.local && source $HOME/.local/bin/activate && poetry install"]
13+
}
14+
}

0 commit comments

Comments
 (0)