Skip to content

cli: Include the failed command's output in error results - #1358

Draft
Christof Marti (chrmarti) wants to merge 1 commit into
mainfrom
chrmarti/error-output
Draft

Christof Marti (chrmarti) wants to merge 1 commit into
mainfrom
chrmarti/error-output

Conversation

@chrmarti

Copy link
Copy Markdown
Contributor

When devcontainer up, set-up, build or run-user-commands fails, the JSON result only has the failed command line as message and a generic description (e.g. "An error occurred setting up the container."). The actual error, for example Docker's Error response from daemon: ..., is only in the log output, which makes failures reported by callers like the Dev Containers extension hard to diagnose.

This adds an errorOutput property to the error results with the end of the failed command's output:

  • Uses the terminal output for commands run with a PTY (e.g. docker run, TTY builds) and the standard error otherwise (e.g. non-TTY builds, Docker Compose), following originalError from the ContainerError to the failed command.
  • Strips terminal control sequences, keeps only the final state of lines rewritten with a carriage return (progress output) and drops blank lines.
  • Limited to the last 20 lines and 2000 characters. Omitted when there is no command output.

Example with "runArgs": ["--network", "missing"]:

{
  "outcome": "error",
  "message": "Command failed: docker run --sig-proxy=false -a STDOUT -a STDERR --mount ... --network missing ...",
  "description": "An error occurred setting up the container.",
  "errorOutput": "docker: Error response from daemon: failed to set up container networking: network missing not found\nRun 'docker run --help' for more information",
  ...
}

Testing:

  • New unit test src/test/errors.test.ts drives the real runCommand and runCommandNoPty with failing fake processes.
  • Manually ran the built CLI against Docker 29.9.3 in WSL: a docker run failure (above) and a failing Dockerfile RUN step, where errorOutput ends with BuildKit's ERROR: failed to build: failed to solve: process "..." did not complete successfully: exit code: 3.

The JSON result of up, set-up, build and run-user-commands only had the failed command line as message and a generic description, so the actual error, for example Docker's 'Error response from daemon: ...', was only in the log. The new errorOutput property carries the last lines of the failed command's terminal output or standard error, without terminal control sequences, so callers like the Dev Containers extension can report the cause.

Co-authored-by: Copilot <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant