跳转到正文
报告库
用途分类 / 其他用途

Error Handling Patterns Skill 安全审计

作者说它能做什么(原文)

Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.

第三方安全检查结论

发现安全风险

已检查文件
2
发现的风险
3
会不会运行危险命令?检查是否下载程序后直接运行、让他人远程控制电脑,或藏起要运行的命令。发现 1 项风险
中风险

通用重试装饰器默认重试所有异常,可能重复有副作用的操作

原文依据:3 处
发现了什么

参考实现默认捕获 Exception,并在失败后再次调用任意传入函数;它没有区分临时故障、验证失败或操作是否幂等。

为什么需要注意

若代理把该模式用于扣款、写入、发送消息或创建资源,第一次操作实际成功但响应失败时,重试可能造成重复扣款、重复记录或重复通知。

装饰器的默认异常范围是 Exception,失败后会再次调用任意传入函数,确实可能重复付款、写入或发送消息等非幂等副作用。示例用法把范围收窄到 NetworkError,降低了该具体示例的风险,但默认接口仍支持过宽重试。风险只在用户采用默认值或用于非幂等操作时出现;可要求仅重试明确的瞬时错误,并加入幂等键或重试安全约束。

references/details.md:77来自说明文档打开原文件
def retry(    max_attempts: int = 3,    backoff_factor: float = 2.0,    exceptions: tuple = (Exception,)):    """Retry decorator with exponential backoff."""    def decorator(func: Callable[..., T]) -> Callable[..., T]:        @wraps(func)        def wrapper(*args, **kwargs) -> T:            last_exception = None            for attempt in range(max_attempts):                try:                    return func(*args, **kwargs)                except exceptions as e:                    last_exception = e                    if attempt < max_attempts - 1:                        sleep_time = backoff_factor ** attempt                        time.sleep(sleep_time)                        continue                    raise            raise last_exception
查看另外 2 个位置
references/details.md:87来自说明文档打开原文件
            last_exception = None            for attempt in range(max_attempts):                try:                    return func(*args, **kwargs)                except exceptions as e:                    last_exception = e                    if attempt < max_attempts - 1:                        sleep_time = backoff_factor ** attempt                        time.sleep(sleep_time)                        continue                    raise            raise last_exception
references/details.md:101来自说明文档打开原文件
# Usage@retry(max_attempts=3, exceptions=(NetworkError,))def fetch_data(url: str) -> dict:    response = requests.get(url, timeout=5)    response.raise_for_status()    return response.json()
会不会泄露文件和密钥?检查是否发送含密码或密钥的文件,以及代码里是否直接写了密钥。发现 1 项风险
中风险

建议记录堆栈、元数据和异常文本,可能把敏感内容写入日志

原文依据:4 处
发现了什么

指南明确建议保留堆栈和元数据,并展示记录包含订单 ID 的异常文本。异常消息、堆栈和业务标识符可能包含个人信息、令牌、查询内容或第三方服务返回的数据。

为什么需要注意

如果应用把这些内容发送到集中日志或监控服务,具有日志访问权的人或服务可能看到原本不应披露的用户或账户数据。

该技能主动建议保留堆栈和元数据,并示范把订单 ID 与异常文本写入错误日志。若异常或元数据包含令牌、个人信息、查询内容或第三方响应,这些内容可能进入日志并被日志系统的读者看到。示例不是自动执行代码,因此风险仅在用户采纳该模式且未脱敏时出现;用户可要求作者补充字段白名单、脱敏和生产环境堆栈限制。

SKILL.md:59来自说明文档打开原文件
1. **Fail Fast**: Validate input early, fail quickly2. **Preserve Context**: Include stack traces, metadata, timestamps3. **Meaningful Messages**: Explain what happened and how to fix it4. **Log Appropriately**: Error = log, expected failure = don't spam logs5. **Handle at Right Level**: Catch where you can meaningfully handle
查看另外 3 个位置
SKILL.md:83来自说明文档打开原文件
        # Process payment        try:            payment_result = payment_service.charge(order.total)        except PaymentServiceError as e:            # Log and wrap external service error            logger.error(f"Payment failed for order {order_id}: {e}")            raise ExternalServiceError(                f"Payment processing failed",                service="payment_service",                details={"order_id": order_id, "amount": order.total}            ) from e
SKILL.md:60来自说明文档打开原文件
1. **Fail Fast**: Validate input early, fail quickly2. **Preserve Context**: Include stack traces, metadata, timestamps3. **Meaningful Messages**: Explain what happened and how to fix it
SKILL.md:85来自说明文档打开原文件
            payment_result = payment_service.charge(order.total)        except PaymentServiceError as e:            # Log and wrap external service error            logger.error(f"Payment failed for order {order_id}: {e}")            raise ExternalServiceError(                f"Payment processing failed",                service="payment_service",                details={"order_id": order_id, "amount": order.total}            ) from e
会不会删除文件或一直在后台运行?检查是否大范围删除文件、改写磁盘,或设置自动启动。未发现风险
会不会绕过安全保护?检查是否跳过网站安全验证、开放过多文件权限,或取消操作前的确认。未发现风险
会不会误导 AI 或隐藏内容?检查工作说明是否要求 AI 忽略你的指令、干扰检查结果,或夹带看不见的文字。未发现风险
会不会偷偷改推广链接或收款方?检查是否强制替换推广链接或收款对象,同时要求隐瞒更改。发现 1 项风险
中风险

汇率降级示例可静默采用固定默认值,影响价格或财务决策

原文依据:2 处
发现了什么

示例依次尝试两个 API 和缓存,然后使用 DEFAULT_RATE;辅助函数捕获所有异常并返回 None,且这里没有告警、时效检查或默认值来源验证。

为什么需要注意

如果被用于结算、报价、报表或购买决策,服务故障可能被伪装成有效汇率,造成错误金额、利润损失或误导性财务结果。

汇率示例在两个服务和缓存均无法产生真值时直接采用 DEFAULT_RATE,而辅助函数会吞掉所有异常并返回 None。若该模式用于定价、结算或财务展示,用户可能在不知道数据失败或过期的情况下依据固定值决策。它只是教学示例,未证明会用于真实交易;用户可要求作者说明默认值来源、有效期、告警机制,并限制其不得用于结算。

references/details.md:502来自说明文档打开原文件
# Multiple fallbacksdef get_exchange_rate(currency: str) -> float:    return (        try_function(lambda: api_provider_1.get_rate(currency))        or try_function(lambda: api_provider_2.get_rate(currency))        or try_function(lambda: cache.get_rate(currency))        or DEFAULT_RATE    )def try_function(func: Callable[[], Optional[T]]) -> Optional[T]:    try:        return func()    except Exception:        return None```
查看另外 1 个位置
references/details.md:511来自说明文档打开原文件
def try_function(func: Callable[[], Optional[T]]) -> Optional[T]:    try:        return func()    except Exception:        return None```

Skill 逻辑拆解

5 个说明模块

该 Skill 是错误处理模式的文档指南;主文件要求仅在概览不足时读取随附的详细参考文件。提供的内容没有安装步骤、命令执行要求或凭据请求。

查看原文
SKILL.md:53来自说明文档打开原文件
## Detailed patterns and worked examplesDetailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.

详细参考包含可复制的 Python、TypeScript、Rust 和 Go 示例,以及重试、熔断、错误聚合和降级模式。这些是示例代码,不是由 Skill 自身自动执行的脚本。

查看原文
references/details.md:3来自说明文档打开原文件
## Language-Specific Patterns### Python Error Handling**Custom Exception Hierarchy:**```pythonclass ApplicationError(Exception):
references/details.md:346来自说明文档打开原文件
## Universal Patterns### Pattern 1: Circuit BreakerPrevent cascading failures in distributed systems.```pythonfrom enum import Enum
从这里开始 · 工作说明SKILL.md
error-handling-patterns
连线表示工作说明包含的模块,不是实际运行顺序。点击模块可查看原文。

文件引用关系图

1 处引用
哪些文件发起引用引用了什么
连线表示真实的文件引用,不是运行顺序。点击节点可高亮相关连线,并查看具体文件和原文位置。虚线表示还有文件需要定位。
文件与检查记录2 个文件

检查范围与遗漏

逐文件查看涉及的内容

下方列出本次涉及的原文范围;纳入检查不代表已查清所有问题。

  • SKILL.md已纳入全文
  • references/details.md已纳入全文

这份报告只针对上方版本。我们看了拿到的代码和说明文件,没有实际运行 Skill,也没有检查它另外安装的软件包。因此,这不是“保证安全”的承诺;换了版本或使用环境,结果也可能不同。

  • SKILL.md工作说明
  • references/details.md配套文件

代码和说明中提到的操作

读取文件
SKILL.md:55来自说明文档打开原文件
Detailed pattern documentation lives in `references/details.md`. Read that file when the navigation tier above is insufficient.
references/details.md:239来自说明文档打开原文件
// Result type for operations that can failfn read_file(path: &str) -> Result<String, io::Error> {    let mut file = File::open(path)?;  // ? operator propagates errors
references/details.md:240来自说明文档打开原文件
fn read_file(path: &str) -> Result<String, io::Error> {    let mut file = File::open(path)?;  // ? operator propagates errors    let mut contents = String::new();
连接外部网站
references/details.md:104来自说明文档打开原文件
def fetch_data(url: str) -> dict:    response = requests.get(url, timeout=5)    response.raise_for_status()
references/details.md:216来自说明文档打开原文件
function fetchData(url: string): Promise<Data> {  return fetch(url)    .then((response) => {
读取了多少行
639
文件校验值(用于核对版本)
3877cbb4f52ffba95ec4695fd8aeed454a2863b9d74c72a86b37224b1bdbfb00