agentleFS
guang-lee-cnguang-lee-cn/scaffold-skills/skills/error-code-classification/SKILL.md

error-code-classification

Skill2 starsChanged 12 days agoMITView on GitHub

错误码两面分类与判定流程。设计库/中间件/API 返回码时,判定哪些状态码对外(契约面)、哪些进入可观测(观测面)、承载方式(计数/采样)。触发词:错误码/状态码/返回码/错误模型/错误分类/可观测/error.code。

The file

Files
SKILL.md

错误码两面分类

概念

一个错误码有两个面,不是二选一:

面服务对象要求
契约面(对外)调用方业务决策码少而稳、语义完整、可行动(修配置/重试/降级);进头文件契约 + 文档
观测面(遥测)运维/开发诊断码细而全、可归因(根因类别)、可计数;进 metrics/事件链,不承诺稳定

同一码可两面承载,但粒度不同:对外可能只呈现一个契约码,观测面细分根因类别。

判定流程(每个新状态码过三问)

  1. Q1 对外可见:调用方能看到它且需要据此分支决策?——是 → 契约面(稳定契约 + @scenario 标注);否 → 仅内部。
  2. Q2 归因价值:能独立定位故障根因类别?——是 → 观测面(失败类别计数 + span error.type 属性);否 → 不进,避免遥测噪音。
  3. Q3 路径温度:冷路径(装配期)计数全量(无性能负担);热路径(每请求)需采样(默认关)。

分层(两类错误码别混)

类处置
装配期配置错误码(校验类)契约面 + 观测面计数(reason 区分根因),不进事件链 span(请求生命周期外)
运行期请求级错误码事件链 span 主角(span error status + error.type + 计数)

两层各自过三问,不混。

标准依据

  • Google API Design Guide 错误模型(对外错误模型与内部诊断分离)
  • OTel semantic conventions(error.type = span attribute + counter label,语义对齐可不引 SDK)
  • gRPC 状态码惯例(码少而稳 vs 信息全)

边界

  • OK/成功码两面不进(成功率是独立指标,不属于错误计数)。
  • 上限用预算式校验而非拍绝对数:维度值 × 单位成本 ≤ 预算(随维度联动,比 magic number 正确)。
  • 对外契约码删除/改名 = 破坏契约;观测面 label 变更无承诺。

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.