Skip to main content

opendev_tools_symbol/
error.rs

1//! Error types for symbol operations.
2
3use std::path::PathBuf;
4
5/// Errors that can occur during symbol operations.
6#[derive(Debug, thiserror::Error)]
7pub enum SymbolError {
8    #[error("Missing required argument: {0}")]
9    MissingArgument(&'static str),
10
11    #[error("Invalid identifier: {0}")]
12    InvalidIdentifier(String),
13
14    #[error("File not found: {0}")]
15    FileNotFound(PathBuf),
16
17    #[error("Symbol not found: {0}")]
18    SymbolNotFound(String),
19
20    #[error("LSP error: {0}")]
21    Lsp(String),
22
23    #[error("IO error: {0}")]
24    Io(#[from] std::io::Error),
25
26    #[error("Edit failed: {0}")]
27    EditFailed(String),
28}
29
30/// Tool result following the OpenDev convention.
31#[derive(Debug, Clone, serde::Serialize)]
32pub struct ToolResult {
33    pub success: bool,
34    pub output: String,
35    #[serde(flatten)]
36    pub extra: serde_json::Value,
37}
38
39impl ToolResult {
40    pub fn ok(output: impl Into<String>) -> Self {
41        Self {
42            success: true,
43            output: output.into(),
44            extra: serde_json::Value::Null,
45        }
46    }
47
48    pub fn ok_with(output: impl Into<String>, extra: serde_json::Value) -> Self {
49        Self {
50            success: true,
51            output: output.into(),
52            extra,
53        }
54    }
55
56    pub fn err(output: impl Into<String>) -> Self {
57        Self {
58            success: false,
59            output: output.into(),
60            extra: serde_json::Value::Null,
61        }
62    }
63}