codeprobe-error-handling
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseStandalone Mode
独立模式
If invoked directly (not via the orchestrator), you must first:
- Read for the output contract, execution modes, and constraints.
../codeprobe/shared-preamble.md - Load applicable reference files from based on the project's tech stack.
../codeprobe/references/ - Default to mode unless the user specifies otherwise.
full
如果直接调用(不通过编排器),您必须先执行以下步骤:
- 阅读以了解输出约定、执行模式和约束条件。
../codeprobe/shared-preamble.md - 根据项目技术栈加载中的适用参考文件。
../codeprobe/references/ - 除非用户另行指定,否则默认使用模式。
full
Error Handling & Resilience Checker
错误处理与弹性检查器
Domain Scope
领域范围
This sub-skill detects error handling and resilience issues across these categories:
- Swallowed Exceptions — Empty catch blocks, catch-and-log-only without rethrow/handle
- Missing Error Handling — External API calls without try/catch, unhandled promise rejections
- Error Information — Generic error messages, leaking internals, missing structured responses
- Retry & Circuit Breaker — No timeout on external calls, no retry for transient failures
- Validation — Missing input validation, implicit null assumptions, type coercion bugs
- Transaction Safety — Multi-step DB operations without transactions, missing rollback
- Logging — No logging on critical paths, missing correlation IDs
此子技能可检测以下类别中的错误处理与弹性问题:
- 吞掉的异常 —— 空catch块、仅记录日志但不重新抛出/处理的catch块
- 缺失错误处理 —— 外部API调用未包裹try/catch、未处理的Promise拒绝
- 错误信息问题 —— 通用错误消息、泄露内部信息、缺失结构化响应
- 重试与断路器 —— 外部调用未设置超时、瞬态故障未配置重试
- 验证问题 —— 缺失输入验证、隐式空值假设、类型转换漏洞
- 事务安全性 —— 多步骤数据库操作未使用事务、缺失回滚机制
- 日志问题 —— 关键路径无日志记录、缺失关联ID
What It Does NOT Flag
不标记的内容
- Sensitive data in logs — covered by (
codeprobe-securityprefix). This sub-skill flags missing logging and structural issues like no correlation IDs, not data leakage.SEC - Test files — test exception handling follows different patterns and is expected to be simpler.
- Framework-generated exception handlers (e.g., Laravel's , Next.js error boundaries that are intentionally minimal) — these are scaffolded defaults, not developer oversights.
Handler.php - CLI scripts with intentionally simple error handling (print + exit) — command-line tools often use a valid pattern of printing an error and exiting with a non-zero code.
- Catch blocks that deliberately swallow specific known-harmless exceptions with a comment explaining why — if the developer documented the rationale, respect the decision.
- Issues that are primarily security vulnerabilities (e.g., authentication bypasses, injection, data exposure) even if they also have error handling implications — these are covered by . If both sub-skills flag the same location, the orchestrator will deduplicate and keep the security finding as primary.
codeprobe-security
- 日志中的敏感数据 —— 由(前缀
codeprobe-security)负责检测。此子技能仅标记缺失日志和结构型问题(如无关联ID),不检测数据泄露。SEC - 测试文件 —— 测试用例的异常处理遵循不同模式,通常更简洁,不在检测范围内。
- 框架生成的异常处理器(例如Laravel的、Next.js的极简错误边界)—— 这些是脚手架默认配置,不属于开发者疏漏。
Handler.php - 故意采用简单错误处理的CLI脚本(打印+退出)—— 命令行工具常使用打印错误并以非零码退出的有效模式。
- 带有注释说明原因、故意吞掉特定已知无害异常的catch块 —— 如果开发者已记录理由,则尊重该决策。
- 主要属于安全漏洞的问题(例如身份验证绕过、注入攻击、数据暴露)—— 即使这些问题涉及错误处理,也由负责检测。如果两个子技能标记了同一位置,编排器会去重并优先保留安全检测结果。
codeprobe-security
Detection Instructions
检测说明
Swallowed Exceptions
吞掉的异常
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Empty catch blocks | Search for | Major |
| Catch-log-only without handling | Find catch blocks that only contain a log/print statement but don't rethrow, return an error, or take any recovery action. The exception is swallowed after logging. | Minor |
| Overly broad exception catching | | Major |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 空catch块 | 搜索空主体的 | 主要 |
| 仅记录日志但不处理的catch块 | 查找仅包含日志/打印语句,但不重新抛出、返回错误或采取任何恢复操作的catch块。异常在记录日志后被吞掉。 | 次要 |
| 过于宽泛的异常捕获 | | 主要 |
Missing Error Handling
缺失错误处理
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| External API calls without try/catch | Search for HTTP client calls (Guzzle, axios, fetch, requests, HttpClient), payment SDK calls (Stripe, PayPal), AWS SDK calls, and other external service integrations. Flag when these calls are NOT wrapped in try/catch or .catch(). | Major |
| Unhandled promise rejections | Search for async functions or promise chains without | Major |
| File I/O without error handling | | Minor |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 外部API调用未包裹try/catch | 搜索HTTP客户端调用(Guzzle、axios、fetch、requests、HttpClient)、支付SDK调用(Stripe、PayPal)、AWS SDK调用及其他外部服务集成。当这些调用未被try/catch或.catch()包裹时进行标记。 | 主要 |
| 未处理的Promise拒绝 | 搜索未配置 | 主要 |
| 文件I/O操作未做错误处理 | | 次要 |
Error Information
错误信息问题
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Generic error messages | API responses returning only "Something went wrong", "Internal server error", or similar without error codes or actionable detail for the client. | Minor |
| Leaking internal errors to API consumers | Exception messages, stack traces, SQL errors, or file paths exposed in API JSON/HTML responses. Check error handling middleware configuration. | Major |
| Missing structured error responses | API endpoints returning errors without consistent structure (no error code field, no message field, inconsistent formats across endpoints). | Minor |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 通用错误消息 | API响应仅返回"Something went wrong"、"Internal server error"或类似内容,未提供错误码或可供客户端操作的详细信息。 | 次要 |
| 向API消费者泄露内部错误 | API的JSON/HTML响应中暴露异常消息、堆栈跟踪、SQL错误或文件路径。检查错误处理中间件的配置。 | 主要 |
| 缺失结构化错误响应 | API端点返回的错误无一致结构(无错误码字段、无消息字段、端点间格式不一致)。 | 次要 |
Retry & Circuit Breaker
重试与断路器
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| External service calls without timeout | HTTP client calls without timeout configuration. Guzzle without | Major |
| No retry for transient failures | External API calls that could fail transiently (HTTP 429, 503, network errors) with no retry mechanism. | Minor |
| No circuit breaker for cascading failures | Service-to-service calls in microservice architectures with no circuit breaker or fallback pattern. | Suggestion |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 外部服务调用未设置超时 | 未配置超时的HTTP客户端调用。Guzzle未设置 | 主要 |
| 瞬态故障未配置重试 | 可能发生瞬态故障(HTTP 429、503、网络错误)的外部API调用未配置重试机制。 | 次要 |
| 未配置断路器以防止级联故障 | 微服务架构中的服务间调用未使用断路器或降级模式。 | 建议 |
Validation
验证问题
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Missing input validation before processing | Functions that accept external input (request params, file contents, API payloads) and use them directly without validation. | Major |
| Implicit null assumptions | Accessing properties or calling methods on values that could be null/undefined without null checks. Chaining | Minor |
| Type coercion bugs | PHP | Minor |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 处理前缺失输入验证 | 接收外部输入(请求参数、文件内容、API负载)并直接使用,未做验证的函数。 | 主要 |
| 隐式空值假设 | 访问可能为null/undefined的值的属性或调用其方法,未做空值检查。对可能为null的返回值进行链式 | 次要 |
| 类型转换漏洞 | PHP中在安全敏感比较时使用 | 次要 |
Transaction Safety
事务安全性
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Multi-step DB ops without transactions | Multiple | Critical |
| Transaction without proper rollback | Transaction blocks that catch exceptions but don't rollback, or that have code after the transaction that assumes success without checking. | Major |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 多步骤数据库操作未使用事务 | 连续执行多个 | 严重 |
| 事务未配置正确回滚 | 捕获异常但不执行回滚的事务块,或事务后存在假设操作成功而未做检查的代码。 | 主要 |
Logging
日志问题
| ID Prefix | What to Detect | How to Detect | Severity |
|---|---|---|---|
| No logging on critical failure paths | Catch blocks in critical business logic (payment, auth, order processing) that don't include any logging. Failures happen silently. | Major |
| Missing correlation/request IDs | Log statements in request-handling code without correlation ID, request ID, or trace ID. Makes debugging distributed issues impossible. | Minor |
| ID前缀 | 检测内容 | 检测方式 | 严重程度 |
|---|---|---|---|
| 关键故障路径无日志记录 | 关键业务逻辑(支付、认证、订单处理)中的catch块未包含任何日志记录。故障会静默发生。 | 主要 |
| 缺失关联/请求ID | 请求处理代码中的日志语句未包含关联ID、请求ID或跟踪ID。这会导致无法调试分布式问题。 | 次要 |
ID Prefix & Fix Prompt Examples
ID前缀与修复提示示例
All findings use the prefix, numbered sequentially: , , etc.
ERR-ERR-001ERR-002所有检测结果使用前缀,按顺序编号:、等。
ERR-ERR-001ERR-002Fix Prompt Examples
修复提示示例
- "Wrap the Stripe API call in (line 55) in a try/catch for
PaymentService@charge. Log the error with context (\Stripe\Exception\ApiErrorException,$orderId) and throw a domain-specific$amountwith a user-friendly message."PaymentFailedException - "Add around the order creation flow in
DB::transaction()(lines 40-65) which currently creates an Order, OrderItems, and Payment record in three separate queries. If any step fails, all should roll back."OrderService@create - "Replace the empty catch block at with proper error handling: log the exception with notification context, then decide whether to rethrow (critical notification) or swallow with a metric (non-critical)."
app/Services/NotificationService.php:88 - "Add timeout and retry configuration to the HTTP client call at . Use
ExternalApiClient.php:30for the Guzzle request to handle transient network failures."->timeout(10)->retry(3, 100)
- "将(第55行)中的Stripe API调用包裹在针对
PaymentService@charge的try/catch中。记录包含上下文(\Stripe\Exception\ApiErrorException、$orderId)的错误,并抛出特定领域的$amount,返回用户友好的消息。"PaymentFailedException - "在(第40-65行)的订单创建流程中添加
OrderService@create,当前该流程通过三个独立查询创建Order、OrderItems和Payment记录。若任何步骤失败,所有操作应回滚。"DB::transaction() - "将处的空catch块替换为正确的错误处理:记录包含通知上下文的异常,然后决定是重新抛出(关键通知)还是通过指标吞掉(非关键通知)。"
app/Services/NotificationService.php:88 - "为处的HTTP客户端调用添加超时和重试配置。对Guzzle请求使用
ExternalApiClient.php:30以处理瞬态网络故障。"->timeout(10)->retry(3, 100)