A Two-Year-Old Bug That Let Failed Commitlint Checks Pass
One of my PRs had a commit message like fixed login redirect instead of a conventional fix: .... The CI log showed commitlint rejecting it, but the Travis job still went green. I reran the helper locally with the same message and watched it print the lint error while exiting 0. That was the bug: the message was bad, but the failure never reached the process exit code.
@commitlint/travis-cli runs Git and commitlint through tinyexec's x(). main() relies on a rejected promise to reach its .catch(), which logs and exits 1. During the execa to tinyexec migration in 3c4b0fd1 (September 2024), that assumption broke: execa rejects on non-zero exits, while tinyexec resolves unless throwOnError is set. lint() also returned the result without inspecting exitCode, so a failed lint looked successful.
async function lint(args: string[], nodeOptions: SpawnOptions = {}, input = "") {
const result = x(COMMITLINT, args, {
throwOnError: true,
nodeOptions: {
stdio: ["pipe", "inherit", "inherit"],
...nodeOptions,
},
});
result.process?.stdin?.write(input);
result.process?.stdin?.end();
return result;
}
The fix sets throwOnError: true in both git() and lint(), preserving the stdio and stdin handling but turning a non-zero child exit into a rejection that reaches the existing error handler. I used the same option in git() because a failed git fetch or git stash should stop the process too; otherwise a broken Git step could still produce a misleading success.
The test gap was the fixture: the only commitlint fixture exited 0, so no test ever observed propagation. I added fixtures/commitlint-fail.js, which prints commitlint failed and exits 1, and a CLI test that runs with TRAVIS_COMMITLINT_BIN pointed at it. The assertions are the two things CI actually depends on:
expect(output.exitCode).toBe(1);
expect(output.stderr).toContain("commitlint failed");
Before the change, the same failure produced exit 0. View the pull request on GitHub →