error-handling
它能做什么
这项技能检查代码如何处理错误,尤其是异步任务和 React 组件中的错误。适用于希望应用能优雅地处理失败、并且更易于调试的开发者。
适用场景
- ✓当你的应用在出错后崩溃或变成空白页面的时候。
- ✓当异步请求失败而没有任何消息或日志的时候。
- ✓当你在构建 React 应用,并希望错误被限制在屏幕的某一部分的时候。
技能链接
https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/error-handling/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请检查我的代码,确保错误得到了妥善处理。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会查找没有 try-catch 代码块的异步操作,以及被悄悄忽略的错误。它会建议捕获这些错误、记录有用的上下文,并在 React 中添加错误边界。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Implement proper error handling
Unhandled errors crash applications, create poor user experiences, and make debugging impossible without proper context.
Quick Reference
- Wrap async operations in try-catch blocks
- Use Error Boundaries in React for UI-level error handling
- Log errors with context for debugging
- Always re-throw or handle—never silently swallow errors
Check
Review error handling in this code, ensuring async operations use try-catch and errors are properly logged.
Fix
Add try-catch blocks to async operations and implement error boundaries for React components.
Explain
Explain JavaScript error handling best practices including try-catch, Promise rejection, and error boundaries.
Code Review
Review scripts, client components, and browser execution paths related to Implement proper error handling. Flag exact imports, event handlers, runtime side effects, or blocking operations that violate the rule, and state how the change should be verified in the browser.
For full implementation details, code examples, and framework-specific guidance,
see references/rule.md.
Rule page: https://frontendchecklist.io/rules/javascript/error-handling
常见问题
什么是错误边界?
在 React 中,它是一个组件,能捕获其子组件中的错误,并显示备用内容,而不是让整个屏幕崩溃。
忽略错误可以接受吗?
这项技能说明绝不能悄悄吞掉错误。每个错误都应被处理或继续向上传递。
它会检查 Promise 的拒绝吗?
会。这项技能把未处理的 Promise 拒绝也纳入良好错误处理的范围。
详情
作者的原始描述
Use when reviewing scripts, client components, bundles, or runtime behavior related to Implement proper error handling. Inspect both source code and the browser execution path so fixes target the real bottleneck or bug.
热度
- GitHub 星标
- 75k
- 排名
- #2833
- 许可证
- MIT
- 更新时间
- 2026/10/31
评论
- …
同一仓库的更多技能
frontendchecklist
75k使用命令行工具,依据 380 多条关于无障碍、速度、SEO 和安全的规则,检查前端代码和线上页面。
frontend-checklist-global
75k依据全部 386 条 Front-End Checklist 规则审查前端项目,并为发现的每个问题给出具体修复方法。
404-page
75k检查你的页面缺失提示是否提供有用的链接,并返回真正的 404 状态,帮助迷路的访客找到方向。
about-page
75k审查你的网站是否有清晰的关于页面,说明由谁运营,以建立访客和搜索引擎的信任。