Skip to content

Commit

Permalink
fix(exec): more informative error msg on timeout (#3584)
Browse files Browse the repository at this point in the history
  • Loading branch information
stefreak authored Jan 25, 2023
1 parent 2d8bf03 commit 0808531
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
39 changes: 33 additions & 6 deletions core/src/plugins/exec/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ async function deployPersistentExecService({

if (devModeSpec.statusCommand) {
let ready = false
let lastStatusResult: execa.ExecaReturnBase<string> | undefined

while (!ready) {
await sleep(persistentLocalProcRetryIntervalMs)
Expand All @@ -734,12 +735,37 @@ async function deployPersistentExecService({
const timeElapsedSec = (now.getTime() - startedAt.getTime()) / 1000

if (timeElapsedSec > devModeSpec.timeout) {
throw new TimeoutError(`Timed out waiting for local service ${serviceName} to be ready`, {
serviceName,
statusCommand: devModeSpec.statusCommand,
pid: proc.pid,
timeout: devModeSpec.timeout,
})
let lastResultDescription = ""
if (lastStatusResult) {
lastResultDescription = dedent`\n\nThe last exit code was ${lastStatusResult.exitCode}.\n\n`
if (lastStatusResult.stderr) {
lastResultDescription += `Command error output:\n${lastStatusResult.stderr}\n\n`
}
if (lastStatusResult.stdout) {
lastResultDescription += `Command output:\n${lastStatusResult.stdout}\n\n`
}
}

throw new TimeoutError(
dedent`Timed out waiting for local service ${serviceName} to be ready.
Garden timed out waiting for the command ${chalk.gray(devModeSpec.statusCommand)}
to return status code 0 (success) after waiting for ${devModeSpec.timeout} seconds.
${lastResultDescription}
Possible next steps:
Find out why the configured status command fails.
In case the service just needs more time to become ready, you can adjust the ${chalk.gray("timeout")} value
in your service definition to a value that is greater than the time needed for your service to become ready.
`,
{
serviceName,
statusCommand: devModeSpec.statusCommand,
pid: proc.pid,
timeout: devModeSpec.timeout,
}
)
}

const result = await run({
Expand All @@ -751,6 +777,7 @@ async function deployPersistentExecService({
opts: { reject: false },
})

lastStatusResult = result
ready = result.exitCode === 0
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ services:
persistent: true
devMode:
command: [/bin/sh -c "while true; do sleep 10000; done"]
statusCommand: [/bin/sh -c "exit 1"]
timeout: 1
statusCommand: [/bin/sh -c "echo Status command output; exit 1"]
timeout: 3
deployCommand: []
8 changes: 5 additions & 3 deletions core/test/unit/src/plugins/exec/exec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -830,9 +830,11 @@ describe("exec plugin", () => {
expect(pid).to.be.a("number")
expect(pid).to.be.greaterThan(0)
expect(error.detail.serviceName).to.eql("dev-mode-timeout")
expect(error.detail.statusCommand).to.eql([`/bin/sh -c "exit 1"`])
expect(error.detail.timeout).to.eql(1)
expect(error.message).to.eql(`Timed out waiting for local service dev-mode-timeout to be ready`)
expect(error.detail.statusCommand).to.eql([`/bin/sh -c "echo Status command output; exit 1"`])
expect(error.detail.timeout).to.eql(3)
expect(error.message).to.include(`Timed out waiting for local service dev-mode-timeout to be ready.`)
expect(error.message).to.include(`The last exit code was 1.`)
expect(error.message).to.include(`Command output:\nStatus command output`)
})
})
})
Expand Down

0 comments on commit 0808531

Please sign in to comment.