elastic/elasticsearch · error · GradleException

Failed to call API endpoint to submit updated dependency gra

Error message

Failed to call API endpoint to submit updated dependency graph

What it means

GradleException wrapping IOException or ParseException thrown while executing the Snyk dependency-graph HTTP PUT or while parsing its response entity. This is the transport-level failure, distinct from the non-201 status error at line 72.

Source

Thrown at build-tools-internal/src/main/java/org/elasticsearch/gradle/internal/snyk/UploadSnykDependenciesGraph.java:76

    @TaskAction
    void upload() {
        String endpoint = calculateEffectiveEndpoint();
        CloseableHttpResponse response;
        try (CloseableHttpClient client = HttpClients.createDefault()) {
            HttpPut putRequest = new HttpPut(endpoint);
            putRequest.addHeader("Authorization", "token " + token.get());
            putRequest.addHeader("Content-Type", "application/json");
            putRequest.setEntity(new FileEntity(inputFile.getAsFile().get(), ContentType.APPLICATION_JSON));
            response = client.execute(putRequest);
            int statusCode = response.getCode();
            String responseString = EntityUtils.toString(response.getEntity());
            getLogger().info("Snyk API call response status: " + statusCode);
            if (statusCode != HttpURLConnection.HTTP_CREATED) {
                throw new GradleException("Uploading Snyk Graph failed with http code " + statusCode + ": " + responseString);
            }
            getLogger().info(responseString);
        } catch (IOException | ParseException e) {
            throw new GradleException("Failed to call API endpoint to submit updated dependency graph", e);
        }
    }

    private String calculateEffectiveEndpoint() {
        String url = this.url.get();
        return snykOrganisation.map(id -> url + "?org=" + id).getOrElse(url);
    }

    @Input
    public Property<String> getToken() {
        return token;
    }

    @Input
    public Property<String> getUrl() {
        return url;
    }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Verify network egress to the Snyk endpoint (curl the URL with the token from the same host).
  2. Configure JVM proxy settings (-Dhttps.proxyHost/-Dhttps.proxyPort) if behind a corporate proxy.
  3. Retry the upload task - transient IOExceptions often resolve on the next run.
  4. Inspect the wrapped exception's class to distinguish IOException (network) from ParseException (response parsing).
Defensive patterns

Strategy: retry

Validate before calling

// Pre-flight connectivity check before the upload
try (Socket s = new Socket()) {
    s.connect(new InetSocketAddress(new URL(endpoint).getHost(), 443), 5000);
} catch (IOException e) {
    throw new GradleException("No route to Snyk endpoint " + endpoint, e);
}

Try / catch

IOException last = null;
for (int attempt = 1; attempt <= 3; attempt++) {
    try (CloseableHttpClient client = HttpClients.createDefault()) {
        // execute and return on success
        return;
    } catch (IOException e) {
        last = e;
    }
}
throw new GradleException("Failed to call API endpoint after retries", last);

Prevention

When it happens

Trigger: client.execute(putRequest) raises IOException (DNS failure, connection reset, socket timeout, TLS handshake error) or EntityUtils.toString raises ParseException on a malformed response body.

Common situations: CI agent cannot reach api.snyk.io due to firewall/proxy; corporate TLS inspection breaks the handshake; intermittent network blip; misconfigured http proxyHost system properties; response truncated mid-stream.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/9b676d264e9fc531. Report an issue: GitHub.