error-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTable of Contents
目录
Error Patterns
错误模式
Overview
概述
Standardized error handling patterns for consistent, production-grade behavior across plugins. Provides error classification, recovery strategies, and debugging workflows.
适用于所有插件的标准化错误处理模式,可实现一致的生产级行为。提供错误分类、恢复策略和调试工作流。
When To Use
适用场景
- Building resilient integrations
- Need consistent error handling
- Want graceful degradation
- Debugging production issues
- 构建高韧性集成系统
- 需要统一的错误处理逻辑
- 希望实现优雅降级
- 排查生产环境问题
When NOT To Use
不适用场景
- Project doesn't use the leyline infrastructure patterns
- Simple scripts without service architecture needs
- 项目未使用leyline基础设施模式
- 无服务架构需求的简单脚本
Error Classification
错误分类
By Severity
按严重程度划分
| Level | Action | Example |
|---|---|---|
| Critical | Halt, alert | Auth failure, service down |
| Error | Retry or secondary strategy | Rate limit, timeout |
| Warning | Log, continue | Partial results, deprecation |
| Info | Log only | Non-blocking issues |
| 级别 | 处理动作 | 示例 |
|---|---|---|
| 严重 | 停止运行并告警 | 认证失败、服务宕机 |
| 错误 | 重试或采用备选策略 | 限流、超时 |
| 警告 | 记录日志并继续运行 | 部分结果返回、接口废弃 |
| 信息 | 仅记录日志 | 非阻塞性问题 |
By Recoverability
按可恢复性划分
python
class ErrorCategory(Enum):
TRANSIENT = "transient" # Retry likely to succeed
PERMANENT = "permanent" # Retry won't help
CONFIGURATION = "config" # User action needed
RESOURCE = "resource" # Quota/limit issueVerification: Run the command with flag to verify availability.
--helppython
class ErrorCategory(Enum):
TRANSIENT = "transient" # 重试大概率成功
PERMANENT = "permanent" # 重试无效
CONFIGURATION = "config" # 需要用户操作
RESOURCE = "resource" # 配额/限制问题验证方式: 运行带参数的命令验证功能是否可用。
--helpQuick Start
快速开始
Standard Error Handler
标准错误处理器
python
from leyline.error_patterns import handle_error, ErrorCategory
try:
result = service.execute(prompt)
except RateLimitError as e:
return handle_error(e, ErrorCategory.RESOURCE, {
"retry_after": e.retry_after,
"service": "gemini"
})
except AuthError as e:
return handle_error(e, ErrorCategory.CONFIGURATION, {
"action": "Run 'gemini auth login'"
})Verification: Run the command with flag to verify availability.
--helppython
from leyline.error_patterns import handle_error, ErrorCategory
try:
result = service.execute(prompt)
except RateLimitError as e:
return handle_error(e, ErrorCategory.RESOURCE, {
"retry_after": e.retry_after,
"service": "gemini"
})
except AuthError as e:
return handle_error(e, ErrorCategory.CONFIGURATION, {
"action": "Run 'gemini auth login'"
})验证方式: 运行带参数的命令验证功能是否可用。
--helpError Result
错误结果
python
@dataclass
class ErrorResult:
category: ErrorCategory
message: str
recoverable: bool
suggested_action: str
metadata: dictVerification: Run the command with flag to verify availability.
--helppython
@dataclass
class ErrorResult:
category: ErrorCategory
message: str
recoverable: bool
suggested_action: str
metadata: dict验证方式: 运行带参数的命令验证功能是否可用。
--helpCommon Patterns
通用模式
Authentication Errors (401/403)
认证错误 (401/403)
- Verify credentials exist
- Check token expiration
- Validate permissions/scopes
- Suggest re-authentication
- 验证凭证是否存在
- 检查令牌是否过期
- 校验权限/作用域
- 建议重新认证
Rate Limit Errors (429)
限流错误 (429)
- Extract retry-after header
- Log for quota tracking
- Implement backoff
- Consider alternative service
- 提取retry-after头信息
- 记录日志用于配额追踪
- 实现退避重试机制
- 考虑切换备选服务
Timeout Errors
超时错误
- Increase timeout for retries
- Break into smaller requests
- Use async patterns
- Consider different model
- 增加重试的超时时间
- 拆分为更小的请求
- 使用异步模式
- 考虑切换其他模型
Context Too Large (400)
上下文过大 (400)
- Estimate tokens before request
- Split into multiple requests
- Reduce input content
- Use larger context model
- 请求前预估token数量
- 拆分为多个请求
- 减少输入内容
- 使用更大上下文的模型
Integration Pattern
集成模式
yaml
undefinedyaml
undefinedIn your skill's frontmatter
在你的skill的前置配置中
dependencies: [leyline:error-patterns]
**Verification:** Run the command with `--help` flag to verify availability.dependencies: [leyline:error-patterns]
**验证方式:** 运行带`--help`参数的命令验证功能是否可用。Detailed Resources
详细资源
- Classification: See for error taxonomy
modules/classification.md - Recovery: See for handling patterns
modules/recovery-strategies.md - Agent Damage Control: See for multi-agent error recovery and escalation
modules/agent-damage-control.md
- 分类: 查看了解错误分类体系
modules/classification.md - 恢复: 查看了解处理模式
modules/recovery-strategies.md - Agent损害控制: 查看了解多Agent错误恢复与升级流程
modules/agent-damage-control.md
Exit Criteria
退出准则
- Error classified correctly
- Appropriate recovery attempted
- User-actionable message provided
- Error logged for debugging
- 错误分类准确
- 已尝试合适的恢复策略
- 提供用户可执行的提示信息
- 错误已记录用于调试
Troubleshooting
故障排查
Common Issues
常见问题
Command not found
Ensure all dependencies are installed and in PATH
Permission errors
Check file permissions and run with appropriate privileges
Unexpected behavior
Enable verbose logging with flag
--verbose命令未找到
确保所有依赖已安装且位于PATH中
权限错误
检查文件权限,使用合适的权限运行
意外行为
添加参数启用详细日志
--verbose