Skip to content

fix: propagate script errors instead of silently swallowing them - #4

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1785759388-improve-error-handling
Open

fix: propagate script errors instead of silently swallowing them#4
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1785759388-improve-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

审计了仓库里所有脚本(99script/*10ccdaily/scripts/*)的错误处理,修掉了错误被吞掉或不向外传播的地方。最危险的一处会覆盖用户已有的 crontab:

crontab -l 在“当前用户没有 crontab”时返回非 0,原来的代码把任何非 0 都当成空内容:

# 之前:crontab -l 权限失败/命令报错 -> existing="" -> 已有定时任务被整体覆盖
existing = current.stdout if current.returncode == 0 else ""

现在 read_existing_crontab()(Python)/ read_existing_crontab + has_no_crontab(Bash)只在 stderr 含 no crontab 时视为空,其他失败一律终止安装并保留原 crontab;写入 crontab - 失败也会带上 stderr 报错,而不是抛一个不含输出的 CalledProcessError

其余修复:

  • git_auto.sh
    • log() 不再因日志文件/目录不可写而让整个脚本失败:降级为只写 stderr 并 WARN 一次(原本 mkdir -p ... | tee 失败会在 set -e/pipefail 下静默终止任何一步)。
    • 新增 ERR trap,set -e 触发的退出会打印 exit 码 + 行号 + 失败命令,不再无声退出。
    • 关键 git 步骤(fetch/pull/stash push/add/commit/push 前的重新同步、mkdir、heartbeat 文件写入、exec 9>lockfilechmod +x)都补上了带上下文的 die 信息;pull 冲突时先 rebase --abort/merge --abort 再报错,不留半完成状态。
    • --status 的 fetch 从 >/dev/null 2>&1 改为捕获并打印 git 的真实错误输出。
    • install_cron/uninstall_cron 去掉 mktemp(失败路径会泄漏临时文件),改为内存中拼装。
    • REPO_DIR 改为 ${REPO_DIR:-...},与帮助文本里 REPO_DIR=/abs/path $0 --run 的用法一致。
  • daily_report.py:输出目录/文件的 OSError 变成明确的 SystemExit 提示;--install-cron 会先创建输出目录,否则 cron 每次的重定向都会静默失败。
  • update_repo.shset -eset -Eeuo pipefail + ERR trap,每个 git 步骤都有可读的失败原因;补上 REPO_DIR/remote 存在性检查(原来 cd 失败是静默退出)。
  • run_all.sh:可执行文件缺失时明确报错,单个示例失败不再静默中断整轮,改为收集退出码、结尾打印失败汇总并以非 0 退出。
  • build.sh:检查 cmake/nproc 是否存在,configure/build 失败给出定位信息。
  • report.sh:原来硬编码 /home/luke/00meta/fy/99script/daily_report.py 且无任何检查(换机器就静默失败),改为脚本相对路径 + 存在性检查 + 透传参数与退出码。

验证:bash -nshellcheck 全部通过;在临时 repo 上跑通 --doctor/--status/--run(含 stash→pull→commit→push→stash pop),并构造失败场景(远端 URL 失效、输出目录不可写、非法 --date/--install-cron 参数、日志目录不可写)确认都有明确报错和非 0 退出;--install-cron/--uninstall-cron 在存在其他 cron 任务时保留了这些任务。

Link to Devin session: https://app.devin.ai/sessions/6d4535fd39b04e61afd529b97648b620
Requested by: @AI-1900

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@AI-1900 AI-1900 self-assigned this Aug 3, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant