testcontainers / testcontainers/testcontainers-java

DockerComposeContainer - InvalidExitException stack trace and cause hidden

Open
#4,280 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
8.7k
Forks
1.9k
Avg merge
2d 17h
Merged PRs (30d)
9

Description

While attempting to use the DockerComposeContainer, I was having some difficulty troubleshooting a startup exception, and had to switch to using individual GenericContainer definitions to figure out that the root cause was failure to find an image.

This was made difficult by the fact that InvalidExitExceptions are caught and mapped to a ContainerLaunchException, but without the causing exception being wrapped.

https://github.com/testcontainers/testcontainers-java/blob/master/core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java#L771-L775

        } catch (InvalidExitValueException e) {
            throw new ContainerLaunchException("Local Docker Compose exited abnormally with code " +
                                               e.getExitValue() + " whilst running command: " + cmd);

        }  catch (Exception e) {
            throw new ContainerLaunchException("Error running local Docker Compose command: " + cmd, e);
        }

Is there a reason that the original exception is not included in the ContainerLaunchException?

I was experiencing this issue only while running a maven build which by default hides logs, and while that could probably be tweaked by config to debug it, it seems like supporting this could be easily improved by simply wrapping the exception like so, the same way it is for generic Exception:

        } catch (InvalidExitValueException e) {
            throw new ContainerLaunchException("Local Docker Compose exited abnormally with code " +
                                               e.getExitValue() + " whilst running command: " + cmd, e);

        }  catch (Exception e) {
            throw new ContainerLaunchException("Error running local Docker Compose command: " + cmd, e);
        }

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in core/src/main/java/org/testcontainers/containers/DockerComposeContainer.java at lines 771-775, where InvalidExitValueException is converted to ContainerLaunchException. Run the relevant Docker Compose tests and verify that the original exception is preserved as the cause when the launch fails.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, docker-compose, java
Domain
testing-qa
Issue type
Bug
Difficulty
1/5
Estimated time
Under an hour
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.