pub struct ToolError {
pub code: ErrorCode,
pub message: String,
pub details: Option<HashMap<String, Value>>,
}Expand description
The primary error type that all tool functions must return in their Result.
Fields§
§code: ErrorCodeA machine-readable code for the error category.
message: StringA human-readable, context-specific error message.
details: Option<HashMap<String, Value>>Additional error context as key-value pairs.
Implementations§
Source§impl ToolError
impl ToolError
Sourcepub fn new(code: ErrorCode, message: impl Into<String>) -> Self
pub fn new(code: ErrorCode, message: impl Into<String>) -> Self
Create a new ToolError with the given code and message.
Sourcepub fn with_details(self, details: HashMap<String, Value>) -> Self
pub fn with_details(self, details: HashMap<String, Value>) -> Self
Add details to this error.
Sourcepub fn with_detail(self, key: &str, value: impl Into<Value>) -> Self
pub fn with_detail(self, key: &str, value: impl Into<Value>) -> Self
Add a single detail string to this error.
pub fn internal(message: impl Into<String>) -> Self
pub fn not_found(message: impl Into<String>) -> Self
pub fn invalid_input(message: impl Into<String>) -> Self
pub fn conflict(message: impl Into<String>) -> Self
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ToolError
impl<'de> Deserialize<'de> for ToolError
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Error for ToolError
impl Error for ToolError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0: use the Display impl or to_string()
Source§impl JsonSchema for ToolError
impl JsonSchema for ToolError
Source§fn schema_name() -> String
fn schema_name() -> String
The name of the generated JSON Schema. Read more
Source§fn schema_id() -> Cow<'static, str>
fn schema_id() -> Cow<'static, str>
Returns a string that uniquely identifies the schema produced by this type. Read more
Source§fn json_schema(generator: &mut SchemaGenerator) -> Schema
fn json_schema(generator: &mut SchemaGenerator) -> Schema
Generates a JSON Schema for this type. Read more
Source§fn is_referenceable() -> bool
fn is_referenceable() -> bool
Whether JSON Schemas generated for this type should be re-used where possible using the
$ref keyword. Read moreAuto Trait Implementations§
impl Freeze for ToolError
impl RefUnwindSafe for ToolError
impl Send for ToolError
impl Sync for ToolError
impl Unpin for ToolError
impl UnwindSafe for ToolError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more