Skip to content

armgit / floci

Public Imported from GitHub
0

Light, fluffy, and always free - The AWS Local Emulator alternative

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

Hector Ventura2b091608afa8
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsErrorMessages.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsErrorMessages.java
new file mode 100644
index 0000000000..050baff451
--- /dev/null
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsErrorMessages.java
@@ -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();
+ }
+}
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java
index 683eaf4e6e..f7b494e003 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/AwsQueryController.java
@@ -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");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java
index 3a2c3029bf..dfc91a1439 100644
--- a/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/neptune/NeptuneQueryHandler.java
@@ -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);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java
index f55d6dd4f9..59d1d76433 100644
--- a/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/rds/RdsQueryHandler.java
@@ -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);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java
index 95ff6b8d7d..b0e4bc5754 100644
--- a/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/sqs/SqsQueryHandler.java
@@ -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);
}
}
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryInternalErrorIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryInternalErrorIntegrationTest.java
index ba2113aec2..9a545d56d5 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryInternalErrorIntegrationTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/AwsQueryInternalErrorIntegrationTest.java
@@ -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