TestcontainerEx.Error (testcontainer_ex v0.9.0)

Copy Markdown View Source

Structured error type returned by all public TestcontainerEx functions.

Pattern-match on :code to handle specific failure modes:

case TestcontainerEx.start_container(config) do
  {:ok, container} -> container
  {:error, %TestcontainerEx.Error{code: :timeout}} -> handle_timeout()
  {:error, %TestcontainerEx.Error{code: :pull_failed} = err} ->
    Logger.error("Pull failed: #{err.message}")
end

Summary

Functions

Build a Docker API error.

Build a not-connected error.

Build a port-not-mapped error.

Build a pull failure error.

Build a timeout error with optional context.

Build a wait-strategy failure, including the last container logs.

Wrap an arbitrary error term into a TestcontainerEx.Error if not already one.

Types

code()

@type code() ::
  :timeout
  | :pull_failed
  | :container_start_failed
  | :wait_strategy_failed
  | :connection_refused
  | :docker_api_error
  | :image_not_found
  | :not_connected
  | :port_not_mapped

t()

@type t() :: %TestcontainerEx.Error{
  cause: any(),
  code: code(),
  context: map(),
  message: String.t()
}

Functions

docker_api_error(message, cause \\ nil)

@spec docker_api_error(String.t(), any()) :: t()

Build a Docker API error.

not_connected()

@spec not_connected() :: t()

Build a not-connected error.

port_not_mapped(port)

@spec port_not_mapped(integer()) :: t()

Build a port-not-mapped error.

pull_failed(image, cause)

@spec pull_failed(String.t(), any()) :: t()

Build a pull failure error.

timeout(message, context \\ %{})

@spec timeout(String.t(), map()) :: t()

Build a timeout error with optional context.

wait_strategy_failed(strategy, elapsed_ms, last_logs \\ [])

@spec wait_strategy_failed(atom() | struct(), integer(), [String.t()]) :: t()

Build a wait-strategy failure, including the last container logs.

wrap(err)

@spec wrap(any()) :: t()

Wrap an arbitrary error term into a TestcontainerEx.Error if not already one.