Skip to main content

vibe_tests/base/
error.rs

1//! Test framework error types.
2
3/// Errors that can occur during MCP testing.
4#[derive(Debug)]
5pub enum TestError {
6    /// I/O error reading or writing file.
7    Io(std::io::Error),
8    /// Environment setup failed (OpenSearch, MCP server).
9    Setup(String),
10    /// MCP tool call failed or returned error.
11    ToolCall(ToolCallError),
12    /// Ollama API request failed.
13    Ollama(String),
14    /// Timeout waiting for service to become ready.
15    Timeout(String),
16}
17
18/// MCP tool call error details.
19#[derive(Debug)]
20pub struct ToolCallError {
21    /// Tool called by the model (None if no tool was called).
22    pub tool: Option<String>,
23    /// Arguments passed to the tool (None if no tool was called).
24    pub args: Option<String>,
25    /// MCP error code (e.g. -32602 for invalid params).
26    pub code: i32,
27}
28
29/// Human-readable error message for each variant.
30impl std::fmt::Display for TestError {
31    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
32        match self {
33            TestError::Io(e) => write!(f, "I/O error: {}", e),
34            TestError::Setup(e) => write!(f, "Setup error: {}", e),
35            TestError::ToolCall(e) => write!(f, "Tool call error: {:?}", e),
36            TestError::Ollama(e) => write!(f, "Ollama error: {}", e),
37            TestError::Timeout(e) => write!(f, "Timeout: {}", e),
38        }
39    }
40}
41
42/// Chain the underlying I/O error as the source.
43impl std::error::Error for TestError {
44    fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
45        match self {
46            TestError::Io(e) => Some(e),
47            _ => None,
48        }
49    }
50}
51
52/// Auto-convert I/O errors into TestError::Io.
53impl From<std::io::Error> for TestError {
54    fn from(e: std::io::Error) -> Self {
55        TestError::Io(e)
56    }
57}
58
59/// Result type alias for test operations.
60pub type TestsResult<T> = std::result::Result<T, TestError>;