Sub topic 5
Finding the first real error
This chapter assumes you can read YAML, run shell commands, and open a failed run in the Actions tab. You should already know that a workflow contains jobs and jobs contain steps. The goal here is to pick the one log line that explains a failure and ignore the lines that follow from it.
Root cause and follow-on errors
A failed run often shows many red marks and many error lines. Most of them are consequences. The root cause is the earliest error that is not itself explained by something before it.
Follow-on errors appear for three reasons:
- A step failed, so later steps in the same job were skipped. Skipped steps are grey, not red.
- A tool printed several messages about one problem, such as a stack trace with many frames.
- A job that depends on a failed job (through
needs) was skipped.
Take the baseline workflow from the earlier chapters. If package.json lives in app/, the step npm ci fails, and npm test is skipped. The failed step is the root cause. The skipped step tells you nothing about tests.
A repeatable method
- Open the run and find the first job marked failed. Jobs that were skipped or cancelled are consequences.
- Inside that job, find the first step with a red mark. Steps after it are skipped unless they use
if: failure()orif: always(). - Expand that step. Read from the top, not the bottom. The last lines usually show only the exit code.
- Find the first line that looks like an error:
Error:,ERR!,fatal:,No such file,command not found, or a red annotation. - Read a few lines above it. The cause is often a warning or a path printed just before.
- State the cause in one sentence, then check it against the workflow file.
A worked example
The log for the failing npm ci step looks like this:
Run npm ci
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/runner/work/demo/demo/package.json
npm ERR! errno -2
npm ERR! enoent Could not read package.json
Error: Process completed with exit code 254.The last line is the exit code, which is only a symptom. The first useful line is npm ERR! code ENOENT, and the path line shows where npm looked: the repository root. The file is not there, because it lives in app/. The cause in one sentence: the step ran in the wrong directory.
The fix from the topic's second example sets a default working directory for run steps:
name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: app
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
cache: npm
cache-dependency-path: app/package-lock.json
- run: npm ci
- run: npm testdefaults.run.working-directory applies only to run steps. It does not change uses steps, which is why the cache setting needs its own path.
Cases where the first error is not the cause
- Warnings before the error. A deprecation or "cache not found" warning is usually harmless. A warning about a missing file or a version mismatch can be the real cause.
- Parallel test output. Test runners may print results out of order. Look for the first failing test name, then read its own output.
- Matrix jobs. Several jobs can fail for different reasons. Check each failed job separately, because one fix may not cover all of them.
- Failure in a post step. Cleanup steps, such as saving a cache, can fail after your commands succeeded. The step name will start with "Post".
Exercise
A job has five steps. Step 2 is red, steps 3 and 4 are grey, and step 5 uses if: failure() and is red. Which step do you investigate first, and why?
Show answer
Step 2. It is the first red step, so it is the earliest failure. Steps 3 and 4 were skipped because of it. Step 5 ran only because step 2 failed, so its error may be a follow-on problem. Read it afterward to see whether it is independent.
Exercise
A log ends with "Error: Process completed with exit code 1." and has no other red text. Where do you look?
Show answer
Scroll up in the same step. The exit code only reports that the command failed. The message explaining why is printed earlier by the command itself, often in plain text without an "Error" prefix.