handle-errors

v2026.09.24

Apply codebase error handling patterns: Zod validation at boundaries, typed errors, early returns, and retry/backoff. Use when implementing error handling or input validation.

GitHub
安装命令
npx skhub add jimmypaolini/handle-errors
Markdown
SKILL.md

Error Handling Patterns

This skill consolidates error handling conventions across the codebase.

When to Use This Skill

Use when asked to:

  • Validate inputs or parse API payloads
  • Handle errors in server functions
  • Add retry logic or backoff
  • Fix any usage in catch blocks

Core Rules

  • Validate at boundaries with Zod
  • Use unknown in catch blocks and narrow
  • Avoid swallowed errors
  • Prefer early returns over deep nesting

Zod Validation at Boundaries

import { z } from "zod";

const Schema = z.object({
  id: z.string().uuid(),
  limit: z.number().int().positive().optional(),
});

const data = Schema.parse(input);

Typed Error Handling

try {
  await doWork();
} catch (error: unknown) {
  if (error instanceof Error) {
    console.error(error.message);
  } else {
    console.error("Unknown error", error);
  }
}

Retry with Backoff

const MAX_RETRIES = 3;
const BASE_DELAY_MS = 500;

for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
  try {
    return await fetchData();
  } catch (error: unknown) {
    if (attempt === MAX_RETRIES) throw error;
    await new Promise((resolve) =>
      setTimeout(resolve, BASE_DELAY_MS * Math.pow(2, attempt)),
    );
  }
}

References

发现
标签

此技能尚未发布标签。

版本
最新版本元数据

版本

v2026.09.24

发布时间

2026年9月24日

分类

未分类

许可证

MIT

源路径

.agents/skills/handle-errors

默认分支

main

最新提交

5ac136d

Tree SHA

9af071d