[Enhancement]: Add sentinel errors for different error root-causes
Proposal
I am working on a case where a test requires a testcontainer to spin up, run, and then exit, with various different input parameters. The success or failure of the test depends in part on when and how the container fails, if it does at all. Right now, when I create and run the container request, I can get multiple different types of errors. Some examples:
- I can get errors that the container failed to start at all
- The container may have exited, with a non-zero status code
- My request may be misconfigured in some way
Currently, my best bet for handling the different possible failure scenarios is to string match against the message from err.Error(). This is fairly brittle
What I propose is that the go-testcontainers package instead ought to return sentinel errors which indicate where and how an error occurred. That is, that it returns errors wrapped in constants exported by the package
So, in stead of simply returning err, you'd get something like:
...
return nil, ErrNonZeroExitCode
...
// or
...
return nil, fmt.Errorf("%w <some-details-here>", ErrNonZeroExitCode)
...
This would allow the consumer to match against particular error cases with errors.Is, as well getting more details/more control with errors.As. You could for example encode information like the specific status code, what part of the lifecycle it failed in, or logs right at the moment of failure, and then extract that with error.As
Looked a little into it. It looks like this is in large part an inherited issue from docker, whose errors are the ones we're seeing