Skip to content

Empty catch block swallows database exceptions in /status endpoint #218

Description

@chedong

问题描述

/status 端点的数据库查询部分使用了空的 catch 块,静默吞噬所有异常:

} catch (\Throwable $ignored) {}

位置

phpMan.php,新增的 /status 端点,对应 SQLite last_emoji 查询段。

影响

虽然这并非关键路径(状态端点的数据库部分只是装饰性的最后一次增强时间查询),但空 catch 块会导致:

  1. SQLite 查询失败时(死锁、磁盘满、DB 文件损坏等)无任何日志记录
  2. 运维人员排查问题时不知道底层有哪些异常
  3. 违反《PHP Review Guide》中 "Catch specific exceptions, keep context" 的原则

建议

至少记录异常信息:

} catch (\Throwable $e) {
    error_log("Status endpoint cache query failed: " . $e->getMessage());
}

或者更精确地捕获 \SQLite3Exception 并记录日志。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions