Fix GitHub Actions "Process completed with exit code 22"
Exit code 22 in GitHub Actions means curl --fail got an HTTP 4xx or 5xx response. Learn how to see the response body and fix the common causes.
At a glance
- Last reviewed
- Reading time
- 4 min read
Code samples are not run in a live repository. See our editorial standards.
On this page
Process completed with exit code 22 almost always means a curl command run with --fail (or -f) received an HTTP response with status 400 or higher. Exit code 22 is curl’s CURLE_HTTP_RETURNED_ERROR. Re-run the request with --fail-with-body so the log shows the status code and the server’s error message.
GitHub marks any step that exits with a non-zero code as failed and, by default, stops the job. The runner only reports the exit code, so the HTTP details are hidden unless you print them. For a related walkthrough, see Fix ‘Resource not accessible by integration’ (403) in GitHub Actions.
Reproduce the failure
This step fails with exit code 22 because the server returns 404:
name: Test API Endpoint
on: [push]
jobs:
check-endpoint:
runs-on: ubuntu-latest
steps:
- name: Request missing resource
run: |
curl --fail https://httpbin.org/status/404
Without --fail, curl treats an HTTP error as a completed transfer and exits 0. With --fail, curl exits 22 for any status of 400 or higher and normally discards the response body. Redirects (3xx) and successes (2xx) exit 0.
To confirm this is your problem, look at the failed step in the Actions run log. The line before the runner’s exit-code message comes from curl and starts with curl: (22). If you used --silent without --show-error, that line is suppressed, so check the command itself for -f, --fail or a combined short flag such as -fsSL.
See the actual response
Use --fail-with-body (curl 7.76.0 or later) to keep the failing exit code and also save the server’s error payload. The ubuntu-latest image ships a newer curl than that, so the flag is available there.
response_file=$(mktemp)
exit_code=0
http_code=$(curl --silent --show-error \
--fail-with-body \
--write-out "%{http_code}" \
--output "${response_file}" \
"https://api.github.com/nonexistent-endpoint") || exit_code=$?
echo "HTTP status: ${http_code}"
echo "Response body:"
cat "${response_file}"
rm -f "${response_file}"
exit "${exit_code}"
--output sends the body to a file, so --write-out "%{http_code}" is the only thing captured in the variable. --show-error keeps connection-level errors visible when you use --silent. The || exit_code=$? prevents set -e from ending the script before the body is printed.
To verify, run the step again. The log should now show HTTP status: 404 followed by the JSON body the server returned, and the step still fails with exit code 22. That is the correct result: you now have the status and message you need to fix the cause.
If your curl is older than 7.76.0 (for example on a self-hosted runner), --fail-with-body is rejected. Drop --fail, write the body to a file, read %{http_code} and run exit 22 yourself when the code is 400 or higher.
Common causes and fixes
Once you can see the status code, the cause is usually one of these.
| Status | Typical cause | Fix |
|---|---|---|
| 401 or 403 | Missing, expired or under-scoped token | Pass the token in an Authorization header from secrets and check its scopes. Secrets are not available to workflows triggered from forks. |
| 404 | Wrong URL, wrong branch or tag, or a private resource requested without credentials | Print the final URL and check it. GitHub returns 404 for private repositories you cannot access. |
| 404 or 400 | An empty variable in the URL, such as ${{ env.VERSION }} that was never set |
Echo the URL before the request and fail early if a variable is empty. |
| 429 or 403 with a rate-limit message | API rate limit | Authenticate the request, add retries with backoff, or reduce calls. |
| 500, 502, 503 | Temporary server problem | Add --retry 3 --retry-all-errors (curl 7.71.0 or later) or re-run the job. |
If you interpolate ${{ }} expressions from untrusted input, such as a pull request title, directly into a run script, you create a script-injection risk. Pass the value through env: and reference it as a shell variable instead.
Trace the exact command
Add set -x to print each command with its expanded arguments. This exposes empty variables and malformed URLs.
jobs:
debug-script:
runs-on: ubuntu-latest
steps:
- name: Run with xtrace enabled
shell: bash
run: |
set -x
curl --fail-with-body --silent --show-error "https://api.github.com/repos/owner/repo"
echo "Step completed"
With shell: bash, the runner already applies set -e and -o pipefail. With pipefail, a pipeline such as curl ... | jq . reports the last non-zero exit status in the pipeline, so a curl failure with exit code 22 is not hidden by jq succeeding.
To trace every run step in a job, set a shell template. A custom template replaces the default flags, so you must repeat -eo pipefail:
jobs:
debug-all:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -eo pipefail -x {0}
steps:
- name: This step runs with xtrace
run: |
curl --fail-with-body --silent --show-error "https://api.github.com/repos/owner/repo"
To verify, open the step log. Each command appears prefixed with +, including the full curl invocation.
Keep the body when the step must continue
If a later step needs the response, write it to a file and let the step fail normally, then print the file with if: always() or if: failure() in the next step. Do not combine continue-on-error: true with if: failure(): a step with continue-on-error is treated as passed, so failure() is false in the following step.
- name: Call API
run: |
curl --fail-with-body --silent --show-error \
--output response.txt \
--write-out "HTTP %{http_code}\n" \
"https://api.github.com/nonexistent-endpoint"
- name: Print response
if: failure()
run: cat response.txt
Here the first step fails with exit code 22, and the second step runs because the job has failed. The log shows HTTP 404 and then the saved body.
Turn on runner debug logging
If the command line itself is unclear, such as a script generated by another action, set the repository secret or variable ACTIONS_STEP_DEBUG to true and re-run the job. The log then includes extra ::debug:: lines from the runner and from actions. You can add your own with echo "::debug::message". Remove the setting once you have the answer, because it makes logs noisy. For a related walkthrough, see GitHub Actions Secret Not Passed to Script: Causes and Fixes.
Fix and confirm
Fix the cause from the table, then re-run the job. A fixed step finishes without the exit-code error, and --write-out "HTTP %{http_code}\n" prints a 2xx code in the log. If the step still fails, the status code in the log tells you whether the cause is authentication, the URL or the server.
Spotted an error? Report it on our Contact page and see our editorial standards for how we correct articles.