mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-15 23:32:37 +00:00
New modules: error, dispatch, documents, assemble, pages, paths, json. lib.rs keeps Automation, its builders, mod lines and pub use lines.
34 lines
960 B
Rust
34 lines
960 B
Rust
/// Why a tool call failed.
|
|
#[derive(Clone, Debug, PartialEq)]
|
|
pub enum ToolError {
|
|
/// No tool has this name.
|
|
UnknownTool(String),
|
|
/// The arguments don't match the tool's schema.
|
|
InvalidArgs(String),
|
|
/// The tool ran and failed (the message is for the agent to read).
|
|
Failed(String),
|
|
}
|
|
|
|
impl std::fmt::Display for ToolError {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
match self {
|
|
ToolError::UnknownTool(t) => write!(f, "unknown tool {t:?}"),
|
|
ToolError::InvalidArgs(m) | ToolError::Failed(m) => f.write_str(m),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl std::error::Error for ToolError {}
|
|
|
|
pub(crate) type Result<T> = std::result::Result<T, ToolError>;
|
|
|
|
pub(crate) fn failed(e: impl std::fmt::Display) -> ToolError {
|
|
ToolError::Failed(e.to_string())
|
|
}
|
|
|
|
impl From<pdfcraft_engine::EditError> for ToolError {
|
|
fn from(e: pdfcraft_engine::EditError) -> Self {
|
|
failed(e)
|
|
}
|
|
}
|