ワンクリックで
py2rs-review-r2-error-tracing
[DRAFT] 第 2 轮审查:统一错误与追踪体系。引入 tracing/anyhow/thiserror,让错误能定位到文件 / 函数 / 调用链。允许小改。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
メニュー
[DRAFT] 第 2 轮审查:统一错误与追踪体系。引入 tracing/anyhow/thiserror,让错误能定位到文件 / 函数 / 调用链。允许小改。
Codex または Claude でインストール この Prompt をコピーして Codex、Claude、または他のアシスタントに貼り付けると、Skill ページを確認してインストールできます。
SOC 職業分類に基づく
Convert Markdown with LaTeX math, images, and tables into a polished PDF. Two rendering engines: (1) weasyprint — pure Python, no browser needed; (2) chromium — best for matrices/bmatrix/pmatrix/vmatrix and complex formulas. Supports Chinese/Japanese fonts. Can chain after ocr-md-polish for a complete OCR→clean→PDF workflow.
Burn core framework - Provides tensor operations, automatic differentiation, and neural network building blocks for Rust deep learning.
Burn CUDA backend - High-performance NVIDIA GPU acceleration. Provides optimal performance for NVIDIA hardware.
Burn Metal backend - Apple GPU acceleration for macOS and iOS. Optimized for Apple Silicon and Intel-based Macs.
Burn NdArray backend - CPU-based tensor operations using Rust's ndarray crate. Ideal for development, testing, and lightweight inference.
Burn ONNX support - Import ONNX models into Burn for inference on any backend. Supports compile-time code generation and runtime loading.
| name | py2rs-review-r2-error-tracing |
| description | [DRAFT] 第 2 轮审查:统一错误与追踪体系。引入 tracing/anyhow/thiserror,让错误能定位到文件 / 函数 / 调用链。允许小改。 |
DRAFT(草稿状态)。具体用哪个日志框架可能改(tracing / log / slog 都有可能)。
rs/src/error.rs —— 统一的 AppError 枚举 + thiserror derive 的模板rs/src/lib.rs 里的 tracing_subscriber::fmt::init() 初始化代码段rust-toolchain.toml ?(如果项目需要固定工具链)reviews/r2-<module>.md 模板 —— 记录本轮引入了哪些 tracing span / error context
anyhow::Result<T>这种全局简写是否合适,也可能在实战里被推翻。 另外:本 skill 仅处理后端代码的错误与追踪。前端 / GUI 的错误展示不属于这里。
**本 skill 必须在 py2rs-review-r0-behavior 与 py2rs-review-r1-rust-style 均完成之后启动。**必须同时满足:
reviews/r0-<module>-signature.md 且显示签名一致(R0 通过)reviews/r1-<module>.md(R1 已产出报告)manifest/modules.yaml 中目标模块状态 ≥ verified若任一未满足,本 skill 直接拒绝启动。
迁移后的代码常见这类问题:
// 味道 A:笼统的 Err
return Err("something failed");
// 味道 B:到处 .expect("..."),没有调用链
let data = fetch().expect("fetch failed");
// 味道 C:没有日志,线上出问题全靠猜
本轮把它推进到:
use thiserror::Error;
use anyhow::{Result, Context};
use tracing::{info, warn, error, info_span};
#[derive(Debug, Error)]
enum AppError {
#[error("user {0} not found")]
UserNotFound(i64),
#[error(transparent)]
Io(#[from] std::io::Error),
}
fn do_work(user_id: i64) -> Result<()> {
let span = info_span!("do_work", user_id);
let _enter = span.enter();
let data = fetch(user_id)
.with_context(|| format!("fetch failed for user {user_id}"))?;
Ok(())
}
若在 py2rs-dep-align 阶段已经加入则跳过,否则补齐:
cargo add thiserror anyhow
cargo add tracing tracing-subscriber
pub fn 返回类型统一为 Result<T, AppError> 或 anyhow::Result<T>thiserror 定义业务错误枚举,给每个错误一个稳定语义(而不是字符串)anyhow::Context / .with_context(|| ...) 给调用链添加上下文unwrap(),除非伴随显式 // safety: ... 注释main.rs(或 lib 的初始化处)调用一次 tracing_subscriber::fmt::init() 或等价初始化info_span! / debug_span!error!(err = ?err),把结构化错误写进日志py2rs-runtime 注入的 trace_id(由 Python 侧传入的上下文)manifest/signatures/<module>.json 中的 raises 列表与 Rust 代码能抛出的业务错误枚举一致PyRuntimeError)thiserror / anyhow / tracing,重构返回类型、增加 span、补充错误上下文cargo build、cargo test 通过tests/compare/<module>.log 仍为 PASSreviews/r2-<module>.md