agentleFS
AsiaOstrichAsiaOstrich/EngramGraph/.agents/skills/error-code-guide/SKILL.md

error-code-guide

Skill4 starsChanged 28 days agoMITView on GitHub

Design consistent error codes following the PREFIX_CATEGORY_NUMBER format. Use when: defining error codes, creating error handling, designing APIs. Not for: log format and levels — use /logging-guide; handling errors that already reached production — use /incident. Keywords: error code, error handling, error format, API errors.

1 other project uses a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

5 rules. About 0 are common, 2 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈2

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Check for existing error code patterns in codebase

    line 224
  2. Very specific:

    Check CONTRIBUTING.md for error code guidelines

    line 225
  3. Very specific:

    If not found, default to PREFIX_CATEGORY_NUMBER format

    line 226
  4. Distinctive:

    If no error code standard found:

    line 230
  5. Very specific:

    After /errors completes, the AI assistant should suggest:

    line 251

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Error Code Guide

Language: English | 繁體中文

Version: 1.0.0 Last Updated: 2025-12-30 Applicability: Claude Code Skills


Core Standard: This skill implements Error Code Standards. For comprehensive methodology documentation, refer to the core standard.

Purpose

This skill helps design consistent error codes following the standard format, enabling better debugging, monitoring, and user experience.

Quick Reference

Error Code Format

<PREFIX>_<CATEGORY>_<NUMBER>
ComponentDescriptionExample
PREFIXApplication/service identifierAUTH, PAY, USR
CATEGORYError categoryVAL, SYS, BIZ
NUMBERUnique numeric identifier001, 100, 404

Examples

AUTH_VAL_001    → Authentication validation error
PAY_SYS_503     → Payment system unavailable
USR_BIZ_100     → User business rule violation
API_NET_408     → API network timeout

Error Categories

CategoryFull NameDescriptionHTTP Status
VALValidationClient input validation failures400
BIZBusinessBusiness rule violations422
SYSSystemInternal system failures500
NETNetworkCommunication failures502/503/504
AUTHAuthSecurity-related errors401/403

Category Code Ranges

RangeDescriptionExample
*_VAL_001-099Field validationMissing required field
*_VAL_100-199Format validationInvalid email format
*_VAL_200-299Constraint validationPassword too short
*_BIZ_001-099State violationsOrder already cancelled
*_BIZ_100-199Rule violationsCannot return after 30 days
*_BIZ_200-299Limit violationsDaily limit exceeded
*_AUTH_001-099AuthenticationInvalid credentials
*_AUTH_100-199AuthorizationInsufficient permissions
*_AUTH_200-299Token/sessionToken expired

HTTP Status Code Mapping

CategoryHTTP StatusDescription
VAL400Bad Request
BIZ422Unprocessable Entity
AUTH (001-099)401Unauthorized
AUTH (100-199)403Forbidden
SYS500Internal Server Error
NET502/503/504Gateway errors

Detailed Guidelines

For complete standards, see:

  • Error Code Standards

AI-Optimized Format (Token-Efficient)

For AI assistants, use the YAML format files for reduced token usage:

  • Base standard: ai/standards/error-codes.ai.yaml

Error Response Format

Single Error

{
  "success": false,
  "error": {
    "code": "AUTH_VAL_001",
    "message": "Email is required",
    "field": "email",
    "requestId": "req_abc123"
  }
}

Multiple Errors

{
  "success": false,
  "errors": [
    {
      "code": "AUTH_VAL_001",
      "message": "Email is required",
      "field": "email"
    },
    {
      "code": "AUTH_VAL_201",
      "message": "Password must be at least 8 characters",
      "field": "password"
    }
  ],
  "requestId": "req_abc123"
}

Internal Error Object

interface ApplicationError {
  // Core fields
  code: string;          // "AUTH_VAL_001"
  message: string;       // Technical message for logs

  // User-facing
  userMessage: string;   // Localized user message
  userMessageKey: string; // i18n key: "error.auth.val.001"

  // Context
  field?: string;        // Affected field: "email"
  details?: object;      // Additional context

  // Debugging
  timestamp: string;     // ISO 8601
  requestId: string;     // Correlation ID
}

Internationalization (i18n)

Message Key Format

error.<prefix>.<category>.<number>

Example Translation Files

# 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: "帳號或密碼錯誤"

Examples

✅ Good Error Codes

AUTH_VAL_001  // Missing required field: email
AUTH_VAL_101  // Invalid email format
ORDER_BIZ_001 // Order already cancelled
ORDER_BIZ_201 // Daily purchase limit exceeded
DB_SYS_001    // Database query failed
SEC_AUTH_001  // Invalid credentials
SEC_AUTH_201  // Token expired

❌ Bad Error Codes

ERR_001       // Too vague, no prefix or category
INVALID       // Not descriptive
error         // Not a code
AUTH_ERROR    // Missing number

Checklist

  • Unique code for each error
  • Category matches error type
  • User message is localized
  • HTTP status is correct
  • Error is documented
  • Code is in registry

Configuration Detection

This skill supports project-specific configuration.

Detection Order

  1. Check for existing error code patterns in codebase
  2. Check CONTRIBUTING.md for error code guidelines
  3. If not found, default to PREFIX_CATEGORY_NUMBER format

First-Time Setup

If no error code standard found:

  1. Suggest: "This project hasn't configured error code standards. Would you like to set up an error code registry?"
  2. Suggest creating errors/registry.ts:
export const ErrorCodes = {
  AUTH_VAL_001: {
    code: 'AUTH_VAL_001',
    httpStatus: 400,
    messageKey: 'error.auth.val.001',
    description: 'Email field is required',
  },
  // ... more codes
} as const;

Next Steps Guidance | 下一步引導

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

Related Standards

  • Error Code Standards
  • Logging Standards

Version History

VersionDateChanges
1.0.02025-12-30Initial release

License

This skill is released under CC BY 4.0.

Source: universal-dev-standards

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.