From 77fca8dcdb1f2e47016812eec1efa4940759a0f9 Mon Sep 17 00:00:00 2001 From: Gaurav Saini <147703805+gauravsaini04@users.noreply.github.com> Date: Mon, 18 Nov 2024 12:06:08 +0000 Subject: [PATCH] issue missing root cause of error #845 solution --- src/spec-common/injectHeadless.ts | 28 ++++++++++++------- .../configs/poetry-example/.devcontainer.json | 14 ++++++++++ 2 files changed, 32 insertions(+), 10 deletions(-) create mode 100644 src/test/configs/poetry-example/.devcontainer.json diff --git a/src/spec-common/injectHeadless.ts b/src/spec-common/injectHeadless.ts index 2e941d075..4b2838132 100644 --- a/src/spec-common/injectHeadless.ts +++ b/src/spec-common/injectHeadless.ts @@ -503,18 +503,26 @@ async function runLifecycleCommand({ lifecycleHook }: ResolverParameters, contai // doesn't get interleaved with the output of other commands. const printMode = name ? 'off' : 'continuous'; const env = { ...(await remoteEnv), ...(await secrets) }; - const { cmdOutput } = await runRemoteCommand({ ...lifecycleHook, output: infoOutput }, containerProperties, typeof postCommand === 'string' ? ['/bin/sh', '-c', postCommand] : postCommand, remoteCwd, { remoteEnv: env, pty: true, print: printMode }); - // 'name' is set when parallel execution syntax is used. - if (name) { - infoOutput.raw(`\x1b[1mRunning ${name} from ${userCommandOrigin}...\x1b[0m\r\n${cmdOutput}\r\n`); - } + try { + const { cmdOutput } = await runRemoteCommand({ ...lifecycleHook, output: infoOutput }, containerProperties, typeof postCommand === 'string' ? ['/bin/sh', '-c', postCommand] : postCommand, remoteCwd, { remoteEnv: env, pty: true, print: printMode }); - infoOutput.event({ - type: 'progress', - name: progressName, - status: 'succeeded', - }); + // 'name' is set when parallel execution syntax is used. + if (name) { + infoOutput.raw(`\x1b[1mRunning ${name} of ${lifecycleHookName} from ${userCommandOrigin}...\x1b[0m\r\n${cmdOutput}\r\n`); + } + } catch (err) { + if (printMode === 'off' && err?.cmdOutput) { + infoOutput.raw(`\r\n\x1b[1m${err.cmdOutput}\x1b[0m\r\n\r\n`); + if (err?.code) { + infoOutput.write(toErrorText(`${lifecycleHookName} failed with exit code ${err.code}. Skipping any further user-provided commands.`)); + } + throw new ContainerError({ + description: `${name ? `${name} of ${lifecycleHookName}` : lifecycleHookName} from ${userCommandOrigin} failed.`, + originalError: err + }); + } + } } infoOutput.raw(`\x1b[1mRunning the ${lifecycleHookName} from ${userCommandOrigin}...\x1b[0m\r\n\r\n`); diff --git a/src/test/configs/poetry-example/.devcontainer.json b/src/test/configs/poetry-example/.devcontainer.json new file mode 100644 index 000000000..cec3b867f --- /dev/null +++ b/src/test/configs/poetry-example/.devcontainer.json @@ -0,0 +1,14 @@ +// Example devcontainer.json configuration, +// wired into the vscode launch task (.vscode/launch.json) +{ + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/devcontainers/features/python:1": { + "version": "latest", + "installTools": "false" + } + }, + "postStartCommand": { + "poetry setup": ["/bin/bash", "-i", "-c", "python3 -m venv $HOME/.local && source $HOME/.local/bin/activate && poetry install"] + } +} \ No newline at end of file