fix(doctor): fail -o json on a failed check and name each product in its hints (#52)

* fix(doctor): fail -o json on a failed check and name each product in its hints

doctor -o json now exits 1 when a check fails, as text output does; hints and HTTP errors name the product's own command (floci gcp start, ...) and the port check falls back to the product's default port; a warnings-only run no longer reads as '0 issue(s) found'; an https AWS_ENDPOINT_URL without a port means 443.

* fix(http): name the product's status command when a request times out

Both ways a request can time out now give the same message with the product's own command. The hint tests use their own local endpoints instead of port 9.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-10-10 18:45:05 -05:00
1 parent 4cd39a957a
commit 771b353733
20 files changed
+266 -35

No files matched your search

@@ -2,12 +2,14 @@ package io.floci.cli.http;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.floci.cli.ProductProfile;
import java.net.ConnectException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpTimeoutException;
import java.time.Duration;
import java.util.ArrayList;
import java.util.List;
@@ -28,6 +30,7 @@ public class FlociHttpClient {
private final String endpoint;
private final String query;
private final String controlPrefix;
private final String commandPrefix;
private final HttpClient http;
public FlociHttpClient(String endpoint) {
@@ -39,6 +42,16 @@ public class FlociHttpClient {
* (e.g. {@code /_floci} for AWS/Azure, {@code /_floci-gcp} for GCP).
*/
public FlociHttpClient(String endpoint, String controlPrefix) {
this(endpoint, controlPrefix, "floci");
}
/** A client for {@code product}'s emulator: its control prefix, and hints that name its tree. */
public FlociHttpClient(String endpoint, ProductProfile product) {
this(endpoint, product.controlPrefix(), product.commandPrefix());
}
private FlociHttpClient(String endpoint, String controlPrefix, String commandPrefix) {
this.commandPrefix = commandPrefix;
// Request paths go before an endpoint's query: http://h:1/?x=1 + /health is http://h:1/health?x=1.
// A fragment is never sent, so it is dropped.
int fragment = endpoint.indexOf('#');
@@ -152,7 +165,7 @@ public class FlociHttpClient {
} catch (FlociException e) {
throw e;
} catch (ConnectException e) {
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try 'floci status' or 'floci start'.");
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try '" + commandPrefix + " status' or '" + commandPrefix + " start'.");
} catch (Exception e) {
throw new FlociException("Request failed: " + e.getMessage());
}
@@ -194,10 +207,12 @@ public class FlociHttpClient {
resp = pending.get(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
pending.cancel(true);
throw new FlociException("No complete response from " + endpoint + path + " within "
+ timeout.toMillis() + " ms. Is Floci running? Try 'floci status'.");
throw timedOut(path, timeout);
} catch (ExecutionException e) {
if (e.getCause() instanceof ConnectException) throw (ConnectException) e.getCause();
// The request's own timeout (no headers yet) can fire just before the one above:
// the same event, so the same message.
if (e.getCause() instanceof HttpTimeoutException) throw timedOut(path, timeout);
throw new FlociException("Request failed: " + e.getCause().getMessage());
}
if (resp.statusCode() >= 400) {
@@ -210,12 +225,17 @@ public class FlociHttpClient {
Thread.currentThread().interrupt();
throw new FlociException("Request interrupted.\nRe-run the command.");
} catch (ConnectException e) {
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try 'floci status' or 'floci start'.");
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try '" + commandPrefix + " status' or '" + commandPrefix + " start'.");
} catch (Exception e) {
throw new FlociException("Request failed: " + e.getMessage());
}
}
private FlociException timedOut(String path, Duration timeout) {
return new FlociException("No complete response from " + endpoint + path + " within "
+ timeout.toMillis() + " ms. Is Floci running? Try '" + commandPrefix + " status'.");
}
@SuppressWarnings("unchecked")
private Map<String, Object> postJson(String path, String body) throws FlociException {
try {
@@ -234,7 +254,7 @@ public class FlociHttpClient {
} catch (FlociException e) {
throw e;
} catch (ConnectException e) {
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try 'floci start'.");
throw new FlociException("Connection refused at " + endpoint + ". Is Floci running? Try '" + commandPrefix + " start'.");
} catch (Exception e) {
throw new FlociException("Request failed: " + e.getMessage());
}