Skip to content

fix: format docker-compose error objects as readable messages#204

Merged
neilime merged 1 commit intomainfrom
copilot/improve-error-log-output
Dec 4, 2025
Merged

fix: format docker-compose error objects as readable messages#204
neilime merged 1 commit intomainfrom
copilot/improve-error-log-output

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 2, 2025

When docker-compose commands fail, the library rejects with { exitCode, err, out } objects. These were being JSON stringified into GitHub Actions error output, producing incomplete, unreadable messages like:

Error: {"exitCode":1,"err":" pgsql Pulling \n consul Pulling \n wordpress Pulling \n redis Pulling \n php-fpm Pulling \n mysql Pulling \n mongodb Pulling \n...

Changes

  • Updated src/services/docker-compose.service.ts: Added error handling in up() and down() methods to catch docker-compose library errors and throw proper Error objects with formatted, readable messages
  • Error formatting logic: Implemented as private methods within DockerComposeService for better separation of concerns

Result

Errors now display as:

Docker Compose command failed with exit code 1

Error output:
pgsql Pulling
consul Pulling
wordpress Pulling
redis Pulling
...

The service-level error handler formats standard Error objects (passes them through), docker-compose results (formats with exit code and context), and falls back to JSON.stringify for unknown types. Deduplicates stderr/stdout when identical and trims whitespace.

Architecture

Error formatting is handled at the service layer where docker-compose errors originate, rather than at the runner level. This provides better separation of concerns and ensures errors are thrown as proper Error instances from the source.

Original prompt

This section details on the original issue you should resolve

<issue_title>The erroneous output is unfriendly, and the cause of the error cannot be found.</issue_title>
<issue_description>An error occurred in the workflow, but the output error log format is json and it is incomplete, making it impossible to determine the cause of the error.

Run hoverkraft-tech/compose-action@v2.4.1
  with:
    compose-file: ./docker-compose.yml
    cwd: /home/runner/work/library/library
    services-log-level: debug
    github-token: ***
  env:
    IMAGE_TAG_PREFIX: 6.0-
    PHP_VERSION: 8.4
Setting up docker compose
docker compose version: 2.38.2
Bringing up docker compose service(s)
Error: {"exitCode":1,"err":" pgsql Pulling \n consul Pulling \n wordpress Pulling \n redis Pulling \n php-fpm Pulling \n mysql Pulling \n mongodb Pulling \n nacos Pulling \n oracle Pulling \n f7b0b443446e Pulling fs layer \n d3746687fc59 Pulling fs layer \n 3820d7bb3a88 Pulling fs layer \n 4f8ebc90375b Pulling fs layer \n bea495abb2fa Pulling fs layer \n 073f36588906 Pulling fs layer \n 4f8ebc90375b Waiting \n bea495abb2fa Waiting \n 073f36588906 Waiting \n 04a32ca23735 Pulling fs layer \n 851012f95aee Pulling fs layer \n 86eab596984c Pulling fs layer \n 073e8c87a452 Pulling fs layer \n b50ff9c82874 Pulling fs layer \n 5aeda0333d98 Pulling fs layer \n fb62a4227561 Pulling fs layer \n 4fc6f3f67d3b Pulling fs layer \n 962936f2812b Pulling fs layer \n 86eab596984c Waiting \n 4975113f25fa Pulling fs layer \n 073e8c87a452 Waiting \n b50ff9c82874 Waiting \n 5aeda0333d98 Waiting \n 962936f2812b Waiting \n fb62a4227561 Waiting \n 4975113f25fa Waiting \n 4fc6f3f67d3b Waiting \n 04a32ca23735 Waiting \n 851012f95aee Waiting \n 2d35ebdb57d9 Already exists \n 0e4bc2bd6656 Pulling fs layer \n 6ee858100e08 Pulling fs layer \n cd3426cf6195 Pulling fs layer \n 3661254f8f9a Pulling fs layer \n fdb87cc80e84 Pulling fs layer \n 724c2bf6b693 Pulling fs layer \n 5c9b8687a229 Pulling fs layer \n eb938a8720e3 Pulling fs layer \n 2f28ba07fe0b Pulling fs layer \n 13706d7eeac1 Pulling fs layer \n 4f4fb700ef54 Pulling fs layer \n e5aea3f34e63 Pulling fs layer \n 0b9e1220d0d5 Pulling fs layer \n 6417e5ed541f Pulling fs layer \n 6d5216183b57 Pulling fs layer \n ea2bccf1088c Pulling fs layer \n ebba470c4e89 Pulling fs layer \n 21cc8a181b25 Pulling fs layer \n 776f2ffaae78 Pulling fs layer \n 15c999bbe313 Pulling fs layer \n eb938a8720e3 Waiting \n 2f28ba07fe0b Waiting \n 13706d7eeac1 Waiting \n 4f4fb700ef54 Waiting \n e5aea3f34e63 Waiting \n 0b9e1220d0d5 Waiting \n 6417e5ed541f Waiting \n 6d5216183b57 Waiting \n ea2bccf1088c Waiting \n ebba470c4e89 Waiting \n 21cc8a181b25 Waiting \n 776f2ffaae78 Waiting \n 15c999bbe313 Waiting \n 0e4bc2bd6656 Waiting \n 6ee858100e08 Waiting \n cd3426cf6195 Waiting \n 3661254f8f9a Waiting \n fdb87cc80e84 Waiting \n 724c2bf6b693 Waiting \n 5c9b8687a229 Waiting \n c3403a2fa49a Pulling fs layer \n 49fc659b0674 Pulling fs layer \n 99c199e41547 Pulling fs layer \n cf5ea62e972b Pulling fs layer \n beb7f844ac8c Pulling fs layer \n d4f9de8b1039 Pulling fs layer \n 6998ffee1d53 Pulling fs layer \n e4d64e20c451 Pulling fs layer \n 36211c80678a Pulling fs layer \n c9f27f614562 Pulling fs layer \n 99c199e41547 Waiting \n cf5ea62e972b Waiting \n beb7f844ac8c Waiting \n d4f9de8b1039 Waiting \n 6998ffee1d53 Waiting \n e4d64e20c451 Waiting \n 36211c80678a Waiting \n c9f27f614562 Waiting \n c3403a2fa49a Waiting \n 49fc659b0674 Waiting \n 0e4bc2bd6656 Pulling fs layer \n a1b0f7b0ca7b Pulling fs layer \n 41062933a099 Pulling fs layer \n ef79fc08e03d Pulling fs layer \n 5e574ea09232 Pulling fs layer \n 3e015c273020 Pulling fs layer \n 3c58e0eb1fc7 Pulling fs layer \n a1b0f7b0ca7b Waiting \n 5e574ea09232 Waiting \n 3e015c273020 Waiting \n 3c58e0eb1fc7 Waiting \n ef79fc08e03d Waiting \n 6ee858100e08 Pulling fs layer \n cd3426cf6195 Pulling fs layer \n 3661254f8f9a Pulling fs layer \n fdb87cc80e84 Pulling fs layer \n 724c2bf6b693 Pulling fs layer \n 5c9b8687a229 Pulling fs layer \n eb938a8720e3 Pulling fs layer \n 2f28ba07fe0b Pulling fs layer \n 13706d7eeac1 Pulling fs layer \n 4f4fb700ef54 Pulling fs layer \n e5aea3f34e63 Pulling fs layer \n e5aea3f34e63 Waiting \n 6ee858100e08 Waiting \n cd3426cf6195 Waiting \n 3661254f8f9a Waiting \n fdb87cc80e84 Waiting \n 724c2bf6b693 Waiting \n 5c9b8687a229 Waiting \n eb938a8720e3 Waiting \n 2f28ba07fe0b Waiting \n 13706d7eeac1 Waiting \n 4f4fb700ef54 Waiting \n 0e4bc2bd6656 Waiting \n 2d35ebdb57d9 Already exists \n 0994e2a6ce3a Pulling fs layer \n ed24ebfd38ba Pulling fs layer \n 3fa9b0a7f3bd Pulling fs layer \n d1fdc01cfb64 Pulling fs layer \n 004c438aca5b Pulling fs layer \n 656ca692f8ee Pulling fs layer \n 40df80557810 Pulling fs layer \n 8444cb202a3f Pulling fs layer \n 7344f10d1096 Pulling fs layer \n 

Link: https://github.com/swoole/library/actions/runs/19858334945/job/56901793149</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix error log output format for better clarity Format docker-compose error objects as readable messages Dec 2, 2025
Copilot AI requested a review from neilime December 2, 2025 19:23
Copy link
Copy Markdown
Member

@neilime neilime left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot this is the job of docker compose service to throw a proper Error. we dont need the error-formatter

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Dec 4, 2025

@copilot this is the job of docker compose service to throw a proper Error. we dont need the error-formatter

You're right! I've moved the error formatting logic to the DockerComposeService class. The service now catches docker-compose library errors and throws proper Error objects with formatted messages. This is a cleaner architecture with better separation of concerns.

Changes in commit c20b3ae:

  • Removed the error-formatter utility
  • Updated DockerComposeService.up() and .down() to catch and format errors internally
  • Reverted changes to index-runner and post-runner (they now receive proper Error objects)
  • Added comprehensive tests for error handling in the service

The error messages remain user-friendly, but the responsibility now correctly belongs to the service layer.

Copilot AI requested a review from neilime December 4, 2025 13:47
@neilime neilime changed the title Format docker-compose error objects as readable messages fix: format docker-compose error objects as readable messages Dec 4, 2025
@neilime neilime marked this pull request as ready for review December 4, 2025 13:49
@neilime neilime force-pushed the copilot/improve-error-log-output branch 2 times, most recently from fd08507 to 155ecb5 Compare December 4, 2025 13:58
@codecov
Copy link
Copy Markdown

codecov bot commented Dec 4, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.38%. Comparing base (e9bb59d) to head (dc56a16).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #204      +/-   ##
==========================================
+ Coverage   97.02%   97.38%   +0.35%     
==========================================
  Files           9        9              
  Lines         168      191      +23     
  Branches       22       29       +7     
==========================================
+ Hits          163      186      +23     
  Misses          5        5              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@neilime neilime force-pushed the copilot/improve-error-log-output branch from 155ecb5 to 14f0ae2 Compare December 4, 2025 14:42
Co-authored-by: neilime <314088+neilime@users.noreply.github.com>
Signed-off-by: Emilien Escalle <emilien.escalle@escemi.com>
@neilime neilime force-pushed the copilot/improve-error-log-output branch from 14f0ae2 to dc56a16 Compare December 4, 2025 14:51
@neilime neilime merged commit 5d59cf2 into main Dec 4, 2025
35 checks passed
@neilime neilime deleted the copilot/improve-error-log-output branch December 4, 2025 14:55
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.

The erroneous output is unfriendly, and the cause of the error cannot be found.

2 participants