prestodb/presto · error · ClientException
Invalid server URL:
Error message
Invalid server URL:
What it means
buildQueryRequest parses session.getServer() with OkHttp's HttpUrl.get, which returns null for URLs that are not valid absolute HTTP(S) URLs; the code then throws ClientException 'Invalid server URL: <url>'. The library cannot even construct the /v1/statement request because the server address is malformed.
Source
Thrown at presto-client/src/main/java/com/facebook/presto/client/StatementClientV1.java:151
this.validateNextUriSource = session.validateNextUriSource();
Request request = buildQueryRequest(session, query);
JsonResponse<QueryResults> response = JsonResponse.execute(QUERY_RESULTS_CODEC, httpClient, request);
if ((response.getStatusCode() != HTTP_OK) || !response.hasValue()) {
state.compareAndSet(State.RUNNING, State.CLIENT_ERROR);
throw requestFailedException("starting query", request, response);
}
processResponse(response.getHeaders(), response.getValue());
this.responseHeaders = toHeaderMap(response.getHeaders());
}
private Request buildQueryRequest(ClientSession session, String query)
{
HttpUrl url = HttpUrl.get(session.getServer());
if (url == null) {
throw new ClientException("Invalid server URL: " + session.getServer());
}
url = url.newBuilder().encodedPath("/v1/statement").build();
Request.Builder builder = prepareRequest(url)
.post(RequestBody.create(MEDIA_TYPE_TEXT, query));
Map<String, String> customHeaders = session.getCustomHeaders();
for (Entry<String, String> entry : customHeaders.entrySet()) {
builder.addHeader(entry.getKey(), entry.getValue());
}
if (session.getSource() != null) {
builder.addHeader(PRESTO_SOURCE, session.getSource());
}
session.getTraceToken().ifPresent(token -> builder.addHeader(PRESTO_TRACE_TOKEN, token));
if (session.getClientTags() != null && !session.getClientTags().isEmpty()) {View on GitHub (pinned to 55bb57d202)
Solutions
- Include an explicit scheme: http://host:port or https://host:port.
- Print/inspect the server string actually passed (check env vars and config substitution).
- Validate the URL with HttpUrl.get(...) or `new URL(...)` before constructing the client.
- Remove whitespace or invalid characters from the server setting.
Example fix
// before presto --server presto.example.com:8080 // after presto --server http://presto.example.com:8080
Defensive patterns
Strategy: validation
Validate before calling
String server = session.getServer();
if (server == null || !server.matches("^https?://[^\s]+$")) {
throw new IllegalArgumentException("Server must be an absolute http(s) URL: " + server);
} Try / catch
try { client.startQuery(session, sql); } catch (ClientException e) { if (e.getMessage().startsWith("Invalid server URL")) { /* fix server config and retry */ } throw e; } Prevention
- Always include http:// or https:// scheme in --server
- Validate config substitution (no leftover ${PLACEHOLDER})
- Trim whitespace from URL settings
- Smoke-test the URL with curl before running queries
When it happens
Trigger: Creating a StatementClientV1 (presto CLI/JDBC startQuery) with a session server string like 'presto.example.com:8080' (no scheme), 'http:/host' (malformed), or containing illegal characters.
Common situations: Forgetting the http:// or https:// scheme; trailing typos or spaces in the --server argument; environment variable/POM substitution leaving a placeholder like ${PRESTO_SERVER}; using ftp:// or a bare hostname.
Understand the failure class
Background: "Invalid URL" / "URL cannot be empty": fix the malformed or missing URL behind request-construction failures — this error's family across 50 libraries.
Related errors
- Illegal character ':' found in username
- Error setting up SSL:
- ACCUMULO_TABLE_EXISTS
- UNEXPECTED_ACCUMULO_ERROR
- NOT_SUPPORTED
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/dddc09977fa4c793.
Report an issue: GitHub.