locales/zh-CN/skills/error-code-guide/SKILL.md
设计一致的错误码,遵循 PREFIX_CATEGORY_NUMBER 格式。 使用时机:定義错误码、建立错误处理、设计 API。 关鍵字:error code, error handling, error format, API errors, 错误码, 错误处理。
npx skillsauth add asiaostrich/universal-dev-standards errorsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
语言: English | 简体中文
版本: 1.0.0 最後更新: 2025-12-30 適用範圍: Claude Code Skills
此技能幫助设计一致的错误码,遵循标准格式,实現更好的除錯、監控和使用者体驗。
<前綴>_<类别>_<编号>
| 元素 | 说明 | 範例 | |------|------|------| | 前綴 (PREFIX) | 应用/服务識别码 | AUTH, PAY, USR | | 类别 (CATEGORY) | 错误类别 | VAL, SYS, BIZ | | 编号 (NUMBER) | 唯一數字識别码 | 001, 100, 404 |
AUTH_VAL_001 → 认证验证错误
PAY_SYS_503 → 付款系统無法使用
USR_BIZ_100 → 使用者商业規則違規
API_NET_408 → API 网络逾时
| 类别 | 全名 | 说明 | HTTP 状态码 | |------|------|------|-------------| | VAL | Validation | 客户端输入验证失败 | 400 | | BIZ | Business | 商业規則違規 | 422 | | SYS | System | 內部系统错误 | 500 | | NET | Network | 通訊错误 | 502/503/504 | | AUTH | Auth | 安全相关错误 | 401/403 |
| 範圍 | 说明 | 範例 | |------|------|------| | *_VAL_001-099 | 欄位验证 | 缺少必填欄位 | | *_VAL_100-199 | 格式验证 | 電子郵件格式無效 | | *_VAL_200-299 | 約束验证 | 密码太短 | | *_BIZ_001-099 | 状态違規 | 订单已取消 | | *_BIZ_100-199 | 規則違規 | 超過 30 天無法退貨 | | *_BIZ_200-299 | 限制違規 | 超過每日限制 | | *_AUTH_001-099 | 认证 | 帳号密码错误 | | *_AUTH_100-199 | 授权 | 权限不足 | | *_AUTH_200-299 | Token/Session | Token 已過期 |
| 类别 | HTTP 状态码 | 说明 | |------|-------------|------| | VAL | 400 | Bad Request | | BIZ | 422 | Unprocessable Entity | | AUTH (001-099) | 401 | Unauthorized | | AUTH (100-199) | 403 | Forbidden | | SYS | 500 | Internal Server Error | | NET | 502/503/504 | Gateway errors |
完整标准請參考:
AI 助手可使用 YAML 格式文件以減少 Token 使用量:
ai/standards/error-codes.ai.yaml{
"success": false,
"error": {
"code": "AUTH_VAL_001",
"message": "電子郵件为必填欄位",
"field": "email",
"requestId": "req_abc123"
}
}
{
"success": false,
"errors": [
{
"code": "AUTH_VAL_001",
"message": "電子郵件为必填欄位",
"field": "email"
},
{
"code": "AUTH_VAL_201",
"message": "密码至少需要 8 个字元",
"field": "password"
}
],
"requestId": "req_abc123"
}
interface ApplicationError {
// 核心欄位
code: string; // "AUTH_VAL_001"
message: string; // 技術消息(用於日誌)
// 使用者界面
userMessage: string; // 本地化使用者消息
userMessageKey: string; // i18n 鍵值: "error.auth.val.001"
// 上下文
field?: string; // 相关欄位: "email"
details?: object; // 附加信息
// 除錯
timestamp: string; // ISO 8601
requestId: string; // 关联 ID
}
error.<前綴>.<类别>.<编号>
# en.yaml
error:
auth:
val:
001: "Email is required"
101: "Invalid email format"
auth:
001: "Invalid credentials"
# zh-TW.yaml
error:
auth:
val:
001: "電子郵件为必填欄位"
101: "電子郵件格式無效"
auth:
001: "帳号或密码错误"
AUTH_VAL_001 // 缺少必填欄位: email
AUTH_VAL_101 // 電子郵件格式無效
ORDER_BIZ_001 // 订单已取消
ORDER_BIZ_201 // 超過每日購买限制
DB_SYS_001 // 数据庫查詢失败
SEC_AUTH_001 // 帳号密码错误
SEC_AUTH_201 // Token 已過期
ERR_001 // 太模糊,没有前綴或类别
INVALID // 不具描述性
error // 不是错误码
AUTH_ERROR // 缺少编号
此技能支援项目特定设置。
CONTRIBUTING.md 中的错误码指南若未找到错误码标准:
errors/registry.ts:export const ErrorCodes = {
AUTH_VAL_001: {
code: 'AUTH_VAL_001',
httpStatus: 400,
messageKey: 'error.auth.val.001',
description: '電子郵件欄位为必填',
},
// ... 更多错误码
} as const;
| 版本 | 日期 | 变更 | |------|------|------| | 1.0.0 | 2025-12-30 | 初始發布 |
此技能採用 CC BY 4.0 授权。
來源: universal-dev-standards
After /errors completes, the AI assistant should suggest:
錯誤碼設計已完成。建議下一步 / Error code design completed. Suggested next steps:
- 執行
/sdd將錯誤碼設計納入正式規格 ⭐ Recommended / 推薦 — 確保錯誤碼在規格中有完整定義 / Ensure error codes are fully defined in specs- 執行
/logging設定結構化日誌以配合錯誤碼 — 讓錯誤碼與日誌系統整合 / Integrate error codes with logging system- 執行
/tdd為錯誤處理邏輯撰寫測試 — 確保每個錯誤碼都有對應的測試 / Ensure each error code has corresponding tests
| Version | Date | Changes | |---------|------|---------| | 1.0.0 | 2025-12-30 | Initial release |
This skill is released under CC BY 4.0.
Source: universal-dev-standards
development
[UDS] 扫描代码库的调试残留与代码质量问题;可自动修正安全模式。 Use when: before committing, during PR review, or periodic codebase cleanup. Keywords: sweep, debug cleanup, console.log, debugger, TODO, ts-any, code quality, 扫描, 清理.
tools
[UDS] 从规格衍生 BDD 场景、TDD 骨架或 ATDD 表格
development
[UDS] 识别重复流程并以正确的开发深度构建 Skill
tools
[UDS] AI 辅助 git push 安全层:质量门禁 + 协作护栏。 Use when: pushing commits, force pushing, pushing to protected branches, pushing feature branches. Keywords: git push, force push, protected branch, quality gate, push receipt, PR automation, 推送, 保护分支, 质量门禁.