lc_testkit/error.rs
1//! lc-testkit error types and the bridge to `ProviderError`.
2
3use lc_providers::ProviderError;
4
5/// Unified lc-testkit error.
6///
7/// Bridges via [`From<TestkitError> for ProviderError`], so the record/replay provider
8/// can be fed directly into generic entry points like chains that require
9/// `L::Error: Into<ProviderError>`.
10#[derive(Debug, thiserror::Error)]
11#[non_exhaustive]
12pub enum TestkitError {
13 /// IO error during recording/replaying (reading/writing files, etc.).
14 #[error("io error while recording/replaying: {0}")]
15 Io(#[from] std::io::Error),
16 /// Replay queue exhausted: more requests than recorded exchanges.
17 #[error("replay queue exhausted (requested {requested} messages, no recording left)")]
18 ReplayExhausted { requested: usize },
19 /// No recording matches the request message signature under `ReplayStrategy::Exact`
20 /// (explicit error, no silent FIFO fallback); `left` is the remaining queue length,
21 /// useful for debugging field drift between the recording and the request.
22 #[error("replay has no recording matching request messages (strategy=Exact, {left} exchange(s) left)")]
23 ReplayNoMatch { left: usize },
24 /// Inner model error, passed through losslessly from the real provider error.
25 #[error("inner model error: {0}")]
26 Inner(#[from] ProviderError),
27}
28
29impl From<TestkitError> for ProviderError {
30 fn from(e: TestkitError) -> Self {
31 match e {
32 // Pass the real provider error through losslessly.
33 TestkitError::Inner(p) => p,
34 // Other errors are testkit's own; they land in `ProviderError::Testkit` via `From<String>`.
35 other => other.to_string().into(),
36 }
37 }
38}