Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add Wade-DevCode/awesome-coding-skills-cn --skill error-handlinggit clone --depth 1 https://github.com/Wade-DevCode/awesome-coding-skills-cnWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/error-handling)<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/error-handling"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/error-handling/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/wade-devcode/awesome-coding-skills-cn/error-handling"><img src="https://agentmods.dev/badge/skills/wade-devcode/awesome-coding-skills-cn/error-handling.svg" alt="Reviewed on agentmods" width="80" height="20"></a>What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00024 | $0.02960 |
| Opus 5.5 | $0.00010 | $0.01184 |
| Sonnet 5.5 | $0.00005 | $0.00592 |
| Haiku 4.5 | $0.00002 | $0.00296 |
Grade A, and why
error-handling scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 207 lines — stays where its author put it; the contents beside it link to each section on GitHub.
错误处理
何时用
- 写任何涉及 IO、网络、数据库、外部 SDK 调用的代码时。
- 在函数/方法中加 try-catch/try-except,需要确定该怎么处理时。
- 联调时前端反馈"不知道哪里出错了"或日志里找不到报错原因时。
- code review 发现 catch 块为空、或者只有
console.log(e)时。
核心规则
1. 不吞异常:catch 块必须有实质处理
规则: catch/except 块里必须有真正的处理动作——记录日志、触发回滚、重新抛出或转换为业务错误;禁止空 catch 块,禁止仅打印后继续正常流程假装没发生过。
为什么: AI 生成代码时,"先写个 try-catch 让它跑起来"是最常见的反模式——catch (e) {} 或 except: pass。空 catch 会把真实的数据库连接失败、磁盘写入错误、第三方 API 超时全部静默吞掉,函数返回"成功",上层完全感知不到异常,日志里没有任何线索,用户看到的是数据没有保存但页面显示"操作成功"。定位这类 bug 通常要花几倍时间,因为所有的证据都被主动销毁了。
怎么做:
- 能处理就处理(重试、降级、返回默认值),并记录 warn 级日志。
- 不能处理就重新抛出(
throw/raise),让上层决定。 - 需要转换语义时,把底层异常包裹成业务异常再抛:
throw new PaymentFailedException("支付网关超时", cause=e)。 finally块做资源清理,不要把清理逻辑写在 catch 里然后 return 提前跳出。
2. 错误分类:可预期错误与意外错误分开处理
规则: 明确区分两类错误——可预期的业务错误(用户输入非法、资源不存在、权限不足)和意外的系统错误(空指针、数据库宕机、bug);前者用业务异常类表达,后者进入全局 handler 并触发告警。
为什么: AI 生成的代码经常把所有异常一律 catch (Exception e) 然后返回 500——校验失败返回 500、资源不存在返回 500、真正的 bug 也是 500。监控告警全是噪音,用户看到的错误信息毫无意义,oncall 工程师不知道哪些 500 需要紧急处理、哪些是正常的业务错误被错误分类了。错误分类是可观测性的基础,混在一起会让整个告警体系失效。
怎么做:
# 业务异常基类(可预期,映射到 4xx)
class AppError(Exception):
def __init__(self, code: str, message: str, http_status: int = 400):
self.code = code
self.message = message
self.http_status = http_status
class ResourceNotFoundError(AppError):
def __init__(self, resource: str, resource_id):
super().__init__("RESOURCE_NOT_FOUND", f"{resource} {resource_id} 不存在", 404)
# 意外错误不捕获,让全局 handler 接管,触发告警
def get_user(user_id: int) -> User:
user = db.query(User).get(user_id)
if user is None:
raise ResourceNotFoundError("User", user_id) # ✅ 业务错误,明确分类
return user
- 业务异常:校验失败、资源不存在、权限不足、业务规则冲突 → 映射到 4xx,记录 info/warn,不触发 PagerDuty。
- 系统异常:数据库连接失败、空指针、未捕获异常 → 5xx,记录 error,触发告警,保留完整堆栈。
3. 错误信息带上下文,但不泄露敏感数据
规则: 错误日志必须包含"哪个操作、哪个输入、在哪一步失败"的上下文;但对外返回的错误信息不能包含数据库表名、SQL 语句、堆栈、密钥、用户密码等敏感内容。
为什么: AI 有两种相反的倾向:要么日志只有 "操作失败" 一句话,查问题像盲人摸象;要么直接把框架抛出的原始异常(含 SQL 语句、文件路径、变量值)直接序列化返回给前端,攻击者可以从中提取数据库结构、推断内部逻辑。两种极端都在真实生产事故中反复出现。
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 207 lines · 24 tokens per session scan A 76d1c0cf20a0
error-handling is a skill published in the GitHub repository Wade-DevCode/awesome-coding-skills-cn (7 stars, last pushed 4mo ago), licensed MIT. It adds 24 tokens to every session and 2,960 once invoked, about $0.0001 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.
Other skills, from other repositories
systematic-debugging
A step-by-step method for finding the underlying cause of technical problems before changing code. It covers reading errors, reproducing failures, checking recent changes, and tracing data across system components.
diagnosing-superpowers
A diagnostic workflow for investigating problems in Superpowers agent sessions using saved conversation records. It requires evidence linked to exact file paths and line numbers, then organizes findings into a report.
brainstorming
A brainstorming workflow for turning an idea into an agreed design before implementation. It requires exploring the project, asking clarifying questions, comparing options, documenting the design, and getting user approval.
executing-plans
A procedure for carrying out a written software implementation plan in a separate session, including reviewing the plan, completing its tasks, and checking the results at defined review points.
chinese-git-workflow
A reference for configuring Git with Chinese code-hosting services such as Gitee, Coding.net, GitLab China, and CNB, including SSH, HTTPS, credentials, CI, and repository mirroring.
chinese-code-review
A Chinese-language code-review communication guide with templates and severity levels for review comments.