fix(core): name the exception class in a message-less Query catch-all (#3728)

An unhandled exception with no message, such as a NullPointerException on
the native image, rendered as "Unexpected error: null" on the Query wire,
which is what the reporter of #3356 saw. The Query controller and the SQS,
RDS and Neptune handlers now fall back to the exception's class name.

Refs #3356
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-16 17:44:38 -05:00
1 parent 3f10acdb95
commit 2b091608af
6 files changed
+39 -4

No files matched your search

@@ -0,0 +1,16 @@
package io.github.hectorvent.floci.core.common;
/**
* Wording for errors that reach a protocol catch-all. A message-less exception (a
* NullPointerException on the native image, where helpful NPE messages are absent) used to
* render as "Unexpected error: null", which told the caller nothing (issue #3356).
*/
public final class AwsErrorMessages {
private AwsErrorMessages() {}
public static String describe(Throwable e) {
String message = e.getMessage();
return message != null && !message.isBlank() ? message : e.getClass().getSimpleName();
}
}
@@ -290,7 +290,7 @@ public class AwsQueryController {
// the Query/XML wire — SDK parsers fail before they can surface anything useful.
LOG.errorv(e, "Unhandled error dispatching Query action {0} for service {1}", action, service);
return xmlErrorResponse("InternalFailure",
"Unexpected error: " + e.getMessage(), 500, "Receiver");
"Unexpected error: " + AwsErrorMessages.describe(e), 500, "Receiver");
}
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.neptune;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsErrorMessages;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsNamespaces;
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
@@ -67,7 +68,7 @@ public class NeptuneQueryHandler {
} catch (Exception e) {
LOG.errorv(e, "Unexpected error in Neptune {0}", action);
return AwsQueryResponse.error("InternalFailure",
"Unexpected error: " + e.getMessage(), AwsNamespaces.RDS, 500);
"Unexpected error: " + AwsErrorMessages.describe(e), AwsNamespaces.RDS, 500);
}
}
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.rds;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsErrorMessages;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsNamespaces;
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
@@ -122,7 +123,7 @@ public class RdsQueryHandler {
} catch (Exception e) {
LOG.errorv(e, "Unexpected error in RDS {0}", action);
return AwsQueryResponse.error("InternalFailure",
"Unexpected error: " + e.getMessage(), AwsNamespaces.RDS, 500);
"Unexpected error: " + AwsErrorMessages.describe(e), AwsNamespaces.RDS, 500);
}
}
@@ -44,7 +44,7 @@ public class SqsQueryHandler {
} catch (Exception e) {
LOG.errorv(e, "Unexpected error in SQS {0}", action);
return AwsQueryResponse.error("InternalError",
"Unexpected error: " + e.getMessage(), AwsNamespaces.SQS, 500);
"Unexpected error: " + AwsErrorMessages.describe(e), AwsNamespaces.SQS, 500);
}
}
@@ -40,6 +40,23 @@ class AwsQueryInternalErrorIntegrationTest {
.body("ErrorResponse.Error.Message", containsString("simulated handler bug"));
}
@Test
void messagelessHandlerExceptionNamesTheExceptionClass() {
// On the native image an NPE carries no message; "Unexpected error: null" is what the
// reporter of #3356 saw. The class name is the least a caller needs to file a report.
when(iamService.listUsers(any())).thenThrow(new NullPointerException());
given()
.formParam("Action", "ListUsers")
.header("Authorization",
"AWS4-HMAC-SHA256 Credential=test/20260227/us-east-1/iam/aws4_request")
.when()
.post("/")
.then()
.statusCode(500)
.body("ErrorResponse.Error.Code", equalTo("InternalFailure"))
.body("ErrorResponse.Error.Message", equalTo("Unexpected error: NullPointerException"));
}
/**
* The catch-all must not swallow AwsException. CloudWatch Metrics is the Query handler that
* renders no error XML of its own, so its AwsException reaches the controller: it has to keep