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 agentmods add skills/lion-1209/coderio/error-handlingnpx skills add Lion-1209/coderio --skill error-handlinggit clone --depth 1 https://github.com/Lion-1209/coderioWhat 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 | $0.00014 | $0.01428 |
| Opus 5 | $0.00007 | $0.00714 |
| Sonnet 5 | $0.00003 | $0.00286 |
| Haiku 4.5 | $0.00001 | $0.00143 |
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 2d 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.
Copies of this mod
1 near-identical copy found in the catalogue:
- error-handling — 100% identical, 0 lines differ
How it starts
The opening of the file, as written. The whole thing — 75 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Error Handling
概述
错误要可观测(知道发生了什么)、可区分(能区分类型)、不吞(不静默 catch)。好的错误处理让你在出问题时能快速定位,而不是对着空白或 undefined 发呆。
何时使用
- 写代码遇到边界/失败场景(空值、超时、外部调用失败),不知怎么处理
- 现有错误处理粗糙(裸 catch、吞异常),要改进
- 设计错误类型/错误码体系
- 决定"这个错该抛还是该处理、要不要重试"
不该用:确定性逻辑(没失败可能,别过度防御)。
核心内容
三态决策:抛 / 处理 / 重试
遇到一个可能的错误,先判断属于哪种:
- 抛(throw / propagate):你处理不了,或属于底层职责。往上传,让上层决策。例:数据库连不上,service 层抛,让调用方决定降级还是报错。
- 处理(handle):你能在原地给出可接受的后续——三种形态:①恢复(用默认值/缓存顶上,如配置缺失用默认配置);②降级(核心功能照跑、非核心跳过,如推荐服务挂了就返回空列表而非整页崩溃);③转成业务语义(把底层异常翻译成业务错误类型抛出,让边界层转成给用户的提示)。业务错误(余额不足、邮箱已注册)归这里——它们不是故障而是预期分支,不重试(结果不会变),抛一个业务错误类型即可。判断"能不能处理"的尺子:**处理后程序能否继续负责任地往下走?**能 → 处理;只是把错藏起来让上层踩坑 → 抛。
- 重试(retry):只对瞬时故障重试——网络抖动、连接超时、HTTP 429/503。指数退避、有上限,耗尽后归为"抛"。三个前提:① 有副作用的调用(支付、下单、写库)重试前必须保证幂等(幂等键或唯一约束),否则重试=重复扣款/重复写入;② 读超时(请求已发出、响应没回来)结果可能已生效,按副作用对待,必须幂等;③ HTTP 429/503 优先遵守响应头
Retry-After。注意 4xx(非 429)和多数 5xx 不是瞬时错误,重试无意义,直接抛。
原则:越靠近错误的层越了解错误含义;但只有能负责任的层才该处理。不知道怎么办就抛上去。
日志
- 记什么:上下文——输入、相关状态、错误对象(含堆栈)
- 敏感信息要脱敏后记,不要完全不记:密码、token、身份证、银行卡——直接丢弃会丢失排查线索("是不是这个用户的请求出问题?")。正确做法是记可识别但不可还原的形式:token 记前 8 位 +
***、手机号记后 4 位、密码只记"是否为空"不记内容。原则:能定位到"是哪个对象/哪次请求",但不能还原出敏感值本身。 - 分级:
debug(排查细节)、info(关键业务节点)、warn(可疑但可继续)、error(出错了需关注)
业务错误 vs 系统错误的日志级别:邮箱已注册、余额不足这类是预期的业务拒绝,不算系统故障——打 info/warn 即可,别打 error 污染告警;DB 连不上、网络失败这类意外故障才打 error。
错误日志要让你光看日志就重现问题现场,而不是只看到 Error: something went wrong。
错误信息面向开发者
错误消息给排查的开发者看,不是给终端用户看:写清发生了什么 + 可能原因 + 怎么排查,并带上下文。
// 差
throw new Error("failed")
// 好
throw new Error(`用户注册失败:邮箱 ${email} 已被注册。检查是否应走登录流程。`)
给用户的提示要另外做(友好、不泄露技术细节),别直接把异常 message 吐给用户。
模式
- 自定义错误类型/错误码:区分业务错误(邮箱已注册)和系统错误(DB 连不上),让上层针对性处理
- fail fast:启动期检查前置条件,不满足直接报错,别带病运行
- 边界统一兜底:在系统边界(HTTP 中间件、API 网关)统一捕获并转换错误,别让内部异常直接漏到外部
- 别 catch 了又原样 throw:要么加上下文再抛,要么处理掉
常见错误
| 问题 | 修法 |
|---|---|
裸 catch(e){} 静默吞错 |
至少记日志 + 决定抛/处理 |
catch 了又 throw e(无添加) |
加上下文再抛,或处理掉 |
日志只记 e.message |
记上下文 + 完整错误对象 |
| 敏感信息要么全记要么全丢 | 脱敏后记(token 记前 8 位 + ***),保留定位能力又不泄露 |
| 把堆栈直接吐给终端用户 | 内部日志详细,给用户友好提示 |
| 不区分错误类型 | 用自定义错误类型/错误码 |
| 无限重试/无退避 | 指数退避 + 最大次数 |
What ships with it
1 file beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
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.
- 2d ago First seen · 75 lines · 14 tokens per session scan A b5b2dcd0c3ba
error-handling is a skill published in the GitHub repository Lion-1209/coderio (9 stars, last pushed 5d ago), licensed MIT. It adds 14 tokens to every session and 1,428 once invoked, about $0.0001 per session on Opus 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
blog-writer
Peri 项目博客写作风格指南。当用户说"写博客"、"写文章"、"出稿"、 "按风格写"、"博客"时触发。也适用于用户丢过来素材说"帮我写篇博客"的场景。 覆盖项目介绍、技术复盘、架构讨论、性能优化、架构设计等类型。.
auto-devflow
Use when starting an issue, bugfix, feature, or refactor that benefits from an adaptive development workflow. Select lite, normal, pro, max, or ultra from task complexity and risk, then use only the coordination, review, and verification phases that the task actually needs.
langfuse
Interact with Langfuse and access its documentation. Use when needing to (1) query or modify Langfuse data programmatically via the CLI — traces, prompts, datasets, scores, sessions, and any other API resource, (2) look up Langfuse documentation, concepts, integration guides, or SDK usage, or (3) understand how any…
self-build
Builds isolated npm capability packages that operate on real project code and connects them to Peri through MCP/MCPP and MetaHarness. Use when adding tools, resources, remote skills or agents, creating a Bun/Node.js stdio server, linking .mcp.json, or changing the active prompt and middleware set.
project-maturity
对任意项目进行全面的成熟度评估扫描。当用户说"检查项目成熟度"、"项目评估"、 "maturity assessment"、"代码质量扫描"、"项目健康度"、"项目体检"、 "scan project maturity"、"项目有多成熟"时触发。适用场景:接手新项目前的摸底、 发布前的质量审查、技术尽调、团队内部代码健康度盘点。.
auto-issue-fixer
Issue 全生命周期管理——从创建到归档。当用户描述技术问题、提 bug、"帮我记录"、 "修一下 X issue"、"验证一下"、"归档 issue"时立即触发。单入口自动分发, 替代旧 issue-create/fix-issue/issue-verify/issue-archive 四个技能。 即使用户没有用"issue"这个词,只要在描述值得追踪的技术问题就应触发。.