fix(backup): answer a missing notification parameter with MissingParameterValueException

PutBackupVaultNotifications lists MissingParameterValueException, "Indicates
that a required parameter is missing", in its Errors section, and we answered
InvalidParameterValueException for both an absent SNSTopicArn and absent
BackupVaultEvents. An SDK maps __type onto a typed exception, so a caller
catching the error AWS documents for this case never saw it.

Present-but-empty keeps InvalidParameterValueException, which is the deliberate
half of the distinction: "BackupVaultEvents": [] was supplied and is unusable,
which is not the same fault as not supplying it. A blank SNSTopicArn is now
treated the same way, where before it collapsed into the missing case.

The controller has to carry the distinction too: readStringList answers an empty
list for an absent member, so the service could not tell [] from absent. It now
passes null when the member is missing or null.

No new exception class or mapper was needed. AwsException takes the error code
as a string and jsonType() passes through any code not in its Query-to-JSON
remapping table, so MissingParameterValueException surfaces as HTTP 400 with
__type MissingParameterValueException. The test asserts that on the wire rather
than trusting it.
This commit is contained in:
Allen Sanborn committed 2026-09-25 09:55:03 -05:00
1 parent 8f5f2c6379
commit 3c4e6321f7
3 files changed
+39 -7

No files matched your search

@@ -147,8 +147,13 @@ public class BackupController {
String body) throws IOException {
String region = regionResolver.resolveRegion(headers);
JsonNode req = objectMapper.readTree(body == null || body.isBlank() ? "{}" : body);
service.putBackupVaultNotifications(vaultName, region,
textOrNull(req, "SNSTopicArn"), readStringList(req.path("BackupVaultEvents")));
// null, not an empty list, when the member is absent: the service answers a missing
// parameter with MissingParameterValueException and an empty one with
// InvalidParameterValueException, and readStringList cannot tell them apart.
JsonNode eventsNode = req.path("BackupVaultEvents");
List<String> events = eventsNode.isMissingNode() || eventsNode.isNull() ? null
: readStringList(eventsNode);
service.putBackupVaultNotifications(vaultName, region, textOrNull(req, "SNSTopicArn"), events);
return Response.noContent().build();
}
@@ -199,11 +199,23 @@ public class BackupService {
public void putBackupVaultNotifications(String vaultName, String region,
String snsTopicArn, List<String> events) {
describeBackupVault(vaultName, region);
if (snsTopicArn == null || snsTopicArn.isBlank()) {
throw new AwsException("InvalidParameterValueException",
// Absent and present-but-empty are different faults and AWS answers them differently.
// PutBackupVaultNotifications lists MissingParameterValueException, "Indicates that a
// required parameter is missing", in its Errors section; a parameter that is present and
// unusable stays InvalidParameterValueException.
if (snsTopicArn == null) {
throw new AwsException("MissingParameterValueException",
"SNSTopicArn is required", 400);
}
if (events == null || events.isEmpty()) {
if (snsTopicArn.isBlank()) {
throw new AwsException("InvalidParameterValueException",
"SNSTopicArn must not be empty", 400);
}
if (events == null) {
throw new AwsException("MissingParameterValueException",
"BackupVaultEvents is required", 400);
}
if (events.isEmpty()) {
throw new AwsException("InvalidParameterValueException",
"BackupVaultEvents must name at least one event", 400);
}
@@ -696,15 +696,30 @@ class BackupIntegrationTest {
@Test
@Order(122)
void notificationsRequireATopicAndAtLeastOneEvent() {
// A missing required parameter is MissingParameterValueException, which the operation
// lists in its Errors section; present-but-empty is InvalidParameterValueException. An
// SDK maps __type to a typed exception, so collapsing the two hands the caller the wrong
// one for a request real AWS names precisely.
given().header("Authorization", AUTH).contentType("application/json")
.body("{\"BackupVaultEvents\":[\"BACKUP_JOB_COMPLETED\"]}")
.when().put("/backup-vaults/" + SUB_VAULT + "/notification-configuration")
.then().statusCode(400).body("__type", equalTo("InvalidParameterValueException"));
.then().statusCode(400)
.body("__type", equalTo("MissingParameterValueException"))
.body("message", containsString("SNSTopicArn"));
given().header("Authorization", AUTH).contentType("application/json")
.body("{\"SNSTopicArn\":\"" + TOPIC + "\"}")
.when().put("/backup-vaults/" + SUB_VAULT + "/notification-configuration")
.then().statusCode(400)
.body("__type", equalTo("MissingParameterValueException"))
.body("message", containsString("BackupVaultEvents"));
given().header("Authorization", AUTH).contentType("application/json")
.body("{\"SNSTopicArn\":\"" + TOPIC + "\",\"BackupVaultEvents\":[]}")
.when().put("/backup-vaults/" + SUB_VAULT + "/notification-configuration")
.then().statusCode(400).body("__type", equalTo("InvalidParameterValueException"));
.then().statusCode(400)
.body("__type", equalTo("InvalidParameterValueException"))
.body("message", containsString("BackupVaultEvents"));
}
@Test