Skip to content

Fix artifact download for non-binary bodies (#621)#738

Open
pmgower wants to merge 1 commit intoNARKOZ:masterfrom
pmgower:fix-artifact-text-download
Open

Fix artifact download for non-binary bodies (#621)#738
pmgower wants to merge 1 commit intoNARKOZ:masterfrom
pmgower:fix-artifact-text-download

Conversation

@pmgower
Copy link
Copy Markdown

@pmgower pmgower commented Apr 26, 2026

Fixes #621.

job_artifacts_download, download_job_artifact_file, and download_branch_artifact_file raise Gitlab::Error::Parsing on any artifact whose response body is not tagged ASCII_8BIT — YAML coverage reports, plain-text logs, CSVs, JUnit XML, etc. The else-branch of each parser proc routes non-binary bodies through Gitlab::Request.parse, which calls JSON.load and re-raises non-JSON input as Gitlab::Error::Parsing.

The issue reports download_job_artifact_file; the same parser proc is duplicated across all three methods, so all three have the bug. Fixing them together. I hit it downloading a YAML coverage report from a GitLab CI job; the issue reporter hit it on a .txt.

The non-binary path is reached for two cases — the # error with json response comment captures one of them:

  1. Error responses with a JSON envelope. Gitlab::Error::ResponseError#initialize calls @response.parsed_response to construct the human-readable error message, so Request.parse is correct here and removing it regresses the error path.
  2. Successful text artifacts. Request.parse is wrong here.

The patch keeps the JSON parse and falls back to FileResponse on Gitlab::Error::Parsing for the second case. Added a 'when successful text response' spec context per method, asserting FileResponse return type, #filename, and #read body content. Existing binary-body and bad-request specs remain green.

rake passes (1377 examples, 0 failures). rake rubocop introduces no new offenses.

job_artifacts_download, download_job_artifact_file, and
download_branch_artifact_file raise Gitlab::Error::Parsing on any
artifact whose response body is not tagged ASCII_8BIT — YAML, plain
text, CSV, JUnit XML, etc. The else-branch of each parser proc routes
non-binary bodies through Gitlab::Request.parse, which calls JSON.load
and re-raises non-JSON input as Gitlab::Error::Parsing.

The non-binary path is reached for two cases: error responses with a
JSON envelope (where Gitlab::Error::ResponseError#initialize relies on
parsed_response to build the error message — Request.parse is correct
here) and successful text artifacts (where it isn't). Keep the JSON
parse and fall back to FileResponse on Gitlab::Error::Parsing.

Add spec coverage for the text-response path on each method.
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.

download_job_artifact_file method fails when the artifact is a non-JSON text file

1 participant