一键导入
error-handling
JOB-255 — replacing Box<dyn Error> on Tool::run with typed ToolError, thiserror patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
JOB-255 — replacing Box<dyn Error> on Tool::run with typed ToolError, thiserror patterns.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | error-handling |
| description | JOB-255 — replacing Box<dyn Error> on Tool::run with typed ToolError, thiserror patterns. |
// Tool trait today
async fn run(&self, input: Value) -> Result<String, Box<dyn Error>>;
async fn call(&self, input: &str) -> Result<String, Box<dyn Error>>;
AgentExecutor receives the error and stringifies it:
Err(err) => format!("The tool return the following error: {}", err)
All error type information is lost. The agent sees a plain string.
## Correct Pattern: Typed Errors in ImplementationsEven while Box<dyn Error> is the return type, define internal typed errors and convert:
use thiserror::Error;
#[derive(Debug, Error)]
enum MyToolError {
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("API request failed: {0}")]
RequestFailed(#[from] reqwest::Error),
#[error("parse error: {0}")]
ParseError(String),
}
pub struct MyTool;
#[async_trait]
impl Tool for MyTool {
async fn run(&self, input: Value) -> Result<String, Box<dyn std::error::Error>> {
let query = input.as_str()
.ok_or_else(|| MyToolError::InvalidInput("expected string".into()))?;
let result = call_api(query).await
.map_err(MyToolError::RequestFailed)?;
Ok(result)
}
// ...
}
## Future ToolError (JOB-255 target)
// Will replace Box<dyn Error> once JOB-255 is implemented
#[derive(Debug, thiserror::Error)]
pub enum ToolError {
#[error("invalid input: {0}")]
InvalidInput(String),
#[error("execution failed: {0}")]
ExecutionFailed(String),
#[error(transparent)]
Other(#[from] Box<dyn std::error::Error + Send + Sync>),
}
Migration: change run() and call() signatures. Update AgentExecutor to pattern-match
ToolError variants and decide whether to break or continue.
Each module already has a typed error via thiserror:
| Module | Error type |
|---|---|
| LLM | LLMError |
| Chain | ChainError |
| Agent | AgentError |
| Embedding | EmbedderError |
| Prompt | PromptError |
| Document loaders | LoaderError |
Use these when implementing new code in those modules. Do not introduce new Box<dyn Error>
return types in non-Tool code.
AgentExecutor, ChatAgent (ReAct), OpenAIToolsAgent, and the Agent trait.
JOB-251 — Why Arc<dyn LLM> over LLMClone, migration pattern, and correct LLM ownership model.
All Chain types — LLMChain, ConversationalChain, SequentialChain, StuffDocuments, ConversationalRetrievalQA, SqlDatabaseChain.
Trait conformance tests, property-based tests (proptest), fuzz targets, and boundary contracts for langchainx traits.
Core langchainx patterns — LLMChain, builder pattern, Chain trait, prompt macros, and basic invocation.
Constructing LLM backends (OpenAI, Claude, DeepSeek, Qwen, Ollama) and configuring CallOptions.