Skip to content
Back to skills

Error Code Classification

ASecurity

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

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added November 13, 2026
ai-agentsgoapi

Works with

  • api

Security analysis

A100/100

Scanned November 13, 2026

npx -y skills add guang-lee-cn/scaffold-skills --skill error-code-classification --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Error Code Classification?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Error Code Classification
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/guang-lee-cn-error-code-classification/badge)](https://www.skillsdirectory.com/skills/guang-lee-cn-error-code-classification)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

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

# 错误码两面分类

## 概念

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

| 面 | 服务对象 | 要求 |
|---|---|---|
| 契约面(对外) | 调用方业务决策 | 码少而稳、语义完整、可行动(修配置/重试/降级);进头文件契约 + 文档 |
| 观测面(遥测) | 运维/开发诊断 | 码细而全、可归因(根因类别)、可计数;进 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 变更无承诺。

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.