Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

A Command That Matched Zero Files Still Exits 0: How to Catch Silent CI Failures

说明与用途

匹配零文件但返回0的命令可能会隐藏CI管道中的错误。添加匹配计数检查或使用如zero‑match‑guard等保护动作可检测这些“静默”失败,提高构建可靠性。

问题

CI pipelines can falsely report success when file‑matching commands like find, grep, or sed process zero items, allowing broken artifacts to reach production.

结果

Adding explicit match count checks or guard actions prevents silent CI failures caused by zero‑match file operations, improving pipeline reliability.

工作流

  • 1. Run a file operation (e.g., find, grep, sed) with a glob pattern.
  • 2. If the command exits 0 but matches zero files, the pipeline silently succeeds.
  • 3. Add a pre‑check: capture the glob expansion into an array and verify its length is >0.
  • 4. Alternatively, use a dedicated action like zero‑match‑guard to assert a minimum match count.
  • 5. If the check fails, exit the job with an error and diagnostic message.

证据

If src/ contains no files matching *.legacy.js, what does find return? It exits with 0.

来源

If your build step changed the output directory structure or filename extensions, dist/**/*.bundle.js might expand to a literal string or match nothing.

来源

To stop silent zero‑match failures, you must enforce strict assertions on file operations before and after execution.

来源

Using zero‑match‑guard in your CI workflow ensures that any file operation or glob expansion explicitly fails the build if the match count falls below an expected threshold.

来源

  • 记录日期: 2026-10-05T11:55:47.992Z