agentsclimarketplace

Error handling

Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/error-handling

🧠 The right skill, one API call. AI agent skills registry with token-efficient skill resolution. 5,000+ skills from 500+ top repos.

Install
npx -y skills add ComeOnOliver/skillshub --skill error-handling

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

What its author says it does

Copied from the file, not written here

Cross-cutting standards for error design, response shapes, error codes, and boundary placement. Use when handling errors, designing exception flows, or standardizing error responses.

SKILL.md

4.1 KB, as published. Nobody here has run it

Common Error Handling Standards

Priority: P1 (OPERATIONAL)

Consistent, predictable error handling is the backbone of maintainable systems. Errors are first-class citizens β€” design them explicitly.

πŸ— Error Response Shape (HTTP APIs)

All API errors MUST use a consistent envelope:

{
  "error": {
    "code": "USER_NOT_FOUND",
    "message": "The requested user does not exist.",
    "traceId": "4bf92f3577b34da6a3ce929d0e0e4736",
    "details": []
  }
}
FieldRule
codeSCREAMING_SNAKE_CASE machine-readable code. Never localize.
messageHuman-readable English summary. Safe for end-users (no stack traces).
traceIdCorrelation ID from the request context.
detailsOptional array of field-level validation errors. Empty for non-validation errors.

πŸ—‚ Error Classification

LayerError TypeStrategy
Validation400 Bad RequestReturn details[] with field paths
Authentication401 UnauthorizedGeneric message β€” never expose reason
Authorization403 ForbiddenLog attempt, never expose role info
Not Found404 Not FoundDistinguishable from auth errors
Conflict409 ConflictInclude conflicting resource ID
Unhandled500 Internal Server ErrorLog full context, return generic message

πŸ“¦ Error Wrapping vs Replacement

  • Wrap when adding context: fmt.Errorf("processOrder: %w", err) (Go) / new ServiceError('msg', { cause: err }) (JS).
  • Replace only when the original error leaks sensitive internal details.
  • Never swallow: Catch without logging or re-throwing hides bugs β€” forbidden.

πŸ›‘ Boundary Placement

  • API Layer: Translate domain/infrastructure errors into HTTP responses. Use a global exception filter/middleware.
  • Domain Layer: Throw domain-specific errors (e.g., InsufficientStockError). Never reference HTTP status codes.
  • Infrastructure Layer: Throw infrastructure errors (e.g., DatabaseConnectionError). Wrap 3rd party exceptions.
  • Never: Let infrastructure errors (raw DB/network exceptions) bubble up to the API response.
Request β†’ [API Layer: maps to HTTP] β†’ [Domain: business errors] β†’ [Infra: DB/network errors]

πŸ”’ Error Code Design

  • Codes are permanent IDs β€” treat them like API contracts. Once published, never rename.
  • Format: <DOMAIN>_<NOUN>_<VERB> β†’ ORDER_PAYMENT_FAILED, USER_EMAIL_DUPLICATE.
  • Define in a centralized constants file; never inline magic strings.

Anti-Patterns

  • No catch(e) {}: Always log or re-throw.
  • No stack traces in responses: Leak internal structure to attackers.
  • No generic 500 for validation: Use 400 with details.
  • No HTTP status codes in domain layer: Domain errors are business concepts, not transport decisions.
  • No error-code proliferation: Prefer a small, well-documented set over one code per exception class.

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.