Skip to content

fix: write downloaded jars as binary and report failed downloads (0.1.4) - #3

Open
bsod90 wants to merge 1 commit into
masterfrom
maxim/binary-safe-downloads
Open

bsod90 wants to merge 1 commit into
masterfrom
maxim/binary-safe-downloads

Conversation

@bsod90

@bsod90 bsod90 commented Nov 3, 2026

Copy link
Copy Markdown
Member

Problem

Since the switch from request to axios (0.1.3), every jar this package downloads is corrupt. axios decodes the response body as UTF-8 text unless responseType says otherwise, and the decoded string is what gets written to disk. Each jar comes out about 1.8x larger and fails to open: unzip -t rejects it, and the JVM reports zip END header not found.

A second bug in the same block: when a request fails (404, network error), the code runs .catch() and then falls into .then() with an undefined response. res.data then throws an unhandled rejection, which crashes the Node process before the caller's callback runs.

Nobody in OSS has hit either bug, because @cubejs-backend/jdbc-driver and @cubejs-backend/databricks-jdbc-driver declare no java.dependencies, so this package never downloads anything for them. Cube Cloud's Microsoft Fabric driver does declare jars (mssql-jdbc, msal4j and their tree). It is still on the unmaintained node-java-maven 0.1.2 (which pulls request), and moving it to this fork is blocked on this fix.

Fix

  • Request responseType: 'arraybuffer' and write the bytes as they are.
  • Handle the success and failure branches separately. A failed download now comes back as download failed for <url> [status: <code>], the same message the request-based version produced. The next step's callback runs outside the promise chain.
  • Bump the version to 0.1.4, so the existing tag-triggered release workflow can publish it.

Evidence

Resolving the Fabric driver's 31 jars from Maven Central into an empty local repository:

resolver jars match Maven Central .sha1 javap on SQLServerDriver
node-java-maven 0.1.2 (request) 31 / 31 loads
@cubejs-backend/node-java-maven 0.1.3 0 / 31 zip END header not found
this branch 31 / 31, byte-identical to 0.1.2 loads

New tests (both fail on master, both pass here):

  • should download jars byte-for-byte as published: resolves ormlite-jdbc and compares each jar's SHA-1 with the .sha1 that Maven Central publishes.
  • should report a missing artifact through the callback: resolves a non-existent artifact and expects the error in the callback instead of a process crash.

The existing seven resolution tests still pass.

#2 targets the same corruption with a stream instead of an arraybuffer, but has no test. Either approach fixes the bytes. This PR also fixes the crash on a failed download.

🤖 Generated with Claude Code

axios decodes a response body as UTF-8 text unless responseType says
otherwise, so every jar written since the request -> axios switch is
corrupt (~1.8x larger, "zip END header not found" in the JVM). Request
an arraybuffer instead.

A failed request (e.g. 404) went through .catch() and then into .then()
with an undefined response, so `res.data` threw an unhandled rejection
that crashed the process before the callback ran. Report it as
"download failed for <url> [status: <code>]", as the request-based
version did.

Tests: jars resolved for ormlite-jdbc must match Maven Central's .sha1,
and a missing artifact must come back through the callback.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

1 participant