Skip to main content

pdk_test/
error.rs

1// Copyright (c) 2026, Salesforce, Inc.,
2// All rights reserved.
3// For full license text, see the LICENSE.txt file
4
5//! Test error handling
6//!
7//! This module defines error types for integration test failures and configuration issues.
8//! It provides comprehensive error handling for Docker operations, service configuration,
9//! and test execution problems.
10//!
11//! ## Primary types
12//! - [`TestError`]: main error enum for test failures and configuration issues
13//! - [`DockerError`]: error type for Docker operations
14//! - [`CredentialRetrievalError`]: error type for credential retrieval operations
15//! - [`UnavailableRuntimeError`]: error type for runtime availability issues
16
17/// Error type for integration tests.
18#[derive(thiserror::Error, Debug)]
19pub enum TestError {
20    /// Represents an startup error.
21    #[error("Startup problem: {0}")]
22    Startup(String),
23
24    /// Represents a low-level I/O error.
25    #[error("Low level I/O problem: {0}")]
26    Io(#[from] std::io::Error),
27
28    /// Represents a low-level Docker error.
29    #[error("Low level Docker problem: {0}")]
30    Docker(#[from] DockerError),
31
32    /// Represents an error indicating a wrong service configuration.
33    #[error("Configuration not supported: {0}")]
34    NotSupportedConfig(String),
35
36    /// Represents an error indicating that there is not a known service with the specified name.
37    #[error("Unknown service of type `{0}`")]
38    UnknownService(&'static str),
39
40    /// Represents an error indicating that there is not a known service with the specified
41    /// hostname.
42    #[error("Unknown service hostname `{0}`")]
43    UnknownServiceHostname(String),
44
45    /// Represents an error indicating that the async runtime was not configured.
46    #[error("Unavailable runtime: {0}")]
47    UnavailableRuntime(#[from] UnavailableRuntimeError),
48
49    /// Represents an error indicating that the underlying async runtime
50    /// does not support multithreading.
51    #[error("Multithread runtime required")]
52    UnavailableMultiThread,
53
54    /// Represents an error there are not ports available to bind services.
55    #[error("Unable to pick new ports")]
56    UnavailablePorts,
57
58    /// Represents an error indicating that the Docker daemon is not available.
59    #[error("Unable to connect to docker daemon.")]
60    UnavailableDocker(DockerError),
61
62    /// Represents an error indicating that credentials cannot be retrieved.
63    #[error("Can not retrieve credentials. Reason: `{0}`")]
64    CredentialRetrieval(#[from] CredentialRetrievalError),
65}
66
67/// A Credential loading error
68#[derive(thiserror::Error, Debug)]
69#[error(transparent)]
70pub struct CredentialRetrievalError(#[from] docker_credential::CredentialRetrievalError);
71
72impl From<docker_credential::CredentialRetrievalError> for TestError {
73    fn from(value: docker_credential::CredentialRetrievalError) -> Self {
74        CredentialRetrievalError(value).into()
75    }
76}
77
78/// A low level Docker error.
79#[derive(thiserror::Error, Debug)]
80#[error(transparent)]
81pub struct DockerError(#[from] bollard::errors::Error);
82
83impl From<bollard::errors::Error> for TestError {
84    fn from(value: bollard::errors::Error) -> Self {
85        DockerError(value).into()
86    }
87}
88
89/// An error indicating that the async runtime was not configured.
90#[derive(thiserror::Error, Debug)]
91#[error(transparent)]
92pub struct UnavailableRuntimeError(#[from] tokio::runtime::TryCurrentError);
93
94impl From<tokio::runtime::TryCurrentError> for TestError {
95    fn from(value: tokio::runtime::TryCurrentError) -> Self {
96        UnavailableRuntimeError(value).into()
97    }
98}