← 返回列表
全部 Skill›工具 Tools›rust-error

rust-error

作者 @BerriAI · 语言 en
Define, wrap, convert, classify, report or test Rust error types in litellm-rust with thiserror. Use when adding an error type or variant, mapping one crate's error into another, turning an error into a gateway response or Python exception, deciding retry or fault from an error, or replacing call sites that build errors from strings
工具 Tools命令行工具通用访问网络待翻译
最近源活动
—
检测 SKILL.md 语言
en
星标 ★
63,561
分支 Fork
0
安装选项
提示
指令
使用 AI 助手安装
将下面的提示复制到你正在使用的 AI 助手中。
下载完整 Skill 目录(含全部配套文件)。 下载压缩包 ↓
SKILL.md 原文预览

Rust errors

crates/http/src/error.rs is the reference implementation. Read the reference for the part you are touching before editing, each one carries the reasoning and worked examples behind its rules

  • shape
  • One top-level Error per crate in src/error.rs. A public enum by default, an opaque struct over a private Repr enum when the variants must stay private. No #[non_exhaustive]
  • A variant is a failure mode a caller handles differently. Provider names and guidance are data, never variants
  • messages and causes
  • Every message is written once, in #[error(...)], and describes its own layer only. Call sites pass typed facts, never a string
  • The cause is the source(), never part of the message. Keep it typed, never stringify or drop it
  • reqwest::Error enters our types only through litellm_http::Error, which strips its URL
  • Anything shown to someone else is rendered with litellm_error::Report, never to_string()
  • conversions
  • One From per source and target pair, only when the conversion needs no context. It classifies and sanitizes once
  • Nest a lower crate's error in one variant. Translate when the meaning changes, never mirror its variants
  • classification
  • Callers ask predicates named after their decision, they do not match nested variants. Predicates match exhaustively
  • Classification states facts. Retry and fallback policy lives with the caller that knows idempotency
  • boundaries
  • An error becomes text for someone else only in one mapping function per error type, in the gateway crates, the Python bridge and host-python. The inference gateway and the bridge decide by the same predicates
  • A failure before the provider was called is a decline. Both ask declined() first and hand it back to the host unchanged
  • gateway
  • One Error with IntoResponse per gateway crate that serves a router. Every failure flows through the same From chain, is classified once in status() and rendered by surface and framing
  • pyo3
  • Two create_exception! classes with the payload in args, ValueError for the caller's fault and RuntimeError otherwise, decoded in failures.py
  • testing
  • Test predicates, chain shape and redaction on errors built the way production builds them
  • recipes
  • Common tasks walked through end to end

The workspace uses thiserror 2 for every error type, and no library crate uses anyhow or Box<dyn Error> in a public signature. The derive docs are the authority on macro behavior, and the std::error::Error docs on what Display and source() mean

评论
BBerriAI
BerriAI
berriai/litellm
查看 GitHub 仓库 查看作者的其他 Skill
来源信息
作者@BerriAI
所属大类工具 Tools / 命令行工具
国内可用性通用
最近源活动—
风险提示访问网络
提示:风险标签为程序静态扫描结果,仅作提示,不代表安全认证。安装前请阅读 SKILL.md 及其引用的脚本、权限,自行判断是否可信。