Skip to content

armgit / floci

Public Imported from GitHub
0

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

refactor(core): build every Smithy validation error through SmithyValidationErrors (#5910)

Kenshin Okinakab55014ddef5c
diff --git a/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java b/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java
index e10ad0d96a..d665f81ae1 100644
--- a/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java
+++ b/src/main/java/io/github/hectorvent/floci/core/common/SmithyValidationErrors.java
@@ -12,6 +12,10 @@ public final class SmithyValidationErrors {
private SmithyValidationErrors() {}
+ /**
+ * The message for one or more violations. An empty list is the caller's bug, so it fails rather
+ * than answering "0 validation errors"; check {@code isEmpty()} before throwing.
+ */
public static String message(List<String> violations) {
if (violations.isEmpty()) {
throw new IllegalArgumentException("no violations to report");
@@ -26,4 +30,35 @@ public final class SmithyValidationErrors {
public static AwsException exception(String errorCode, List<String> violations) {
return new AwsException(errorCode, message(violations), 400);
}
+
+ public static AwsException exception(String errorCode, String violation) {
+ return exception(errorCode, List.of(violation));
+ }
+
+ /** The code most JSON services use, on both the awsJson and the restJson protocols. */
+ public static AwsException validationException(List<String> violations) {
+ return exception("ValidationException", violations);
+ }
+
+ public static AwsException validationException(String violation) {
+ return validationException(List.of(violation));
+ }
+
+ /** The awsQuery protocol's code. */
+ public static AwsException validationError(List<String> violations) {
+ return exception("ValidationError", violations);
+ }
+
+ public static AwsException validationError(String violation) {
+ return validationError(List.of(violation));
+ }
+
+ /** The code of REST JSON services that model their validation failure as BadRequestException. */
+ public static AwsException badRequest(List<String> violations) {
+ return exception("BadRequestException", violations);
+ }
+
+ public static AwsException badRequest(String violation) {
+ return badRequest(List.of(violation));
+ }
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
index 8d8edd98b6..14b798317d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cloudformation/CloudFormationService.java
@@ -11,6 +11,7 @@ import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.AwsRegions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.RequestScopes;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.common.dns.EmbeddedDnsServer;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
@@ -1426,10 +1427,7 @@ public class CloudFormationService implements ResourceProvider {
+ RESOURCE_TO_SKIP.pattern() + "]");
}
if (!violations.isEmpty()) {
- String prefix = violations.size() == 1
- ? "1 validation error detected: "
- : violations.size() + " validation errors detected: ";
- throw new AwsException("ValidationError", prefix + String.join("; ", violations), 400);
+ throw SmithyValidationErrors.validationError(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
index d5ba0fe157..842355ef51 100644
--- a/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/cognito/CognitoService.java
@@ -19,6 +19,7 @@ import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ReservedTags;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
@@ -2070,10 +2071,7 @@ public class CognitoService implements ResourceProvider {
}
private AwsException validationErrors(List<String> errors) {
- String header = errors.size() == 1
- ? "1 validation error detected: "
- : errors.size() + " validation errors detected: ";
- return new AwsException("InvalidParameterException", header + String.join("; ", errors), 400);
+ return SmithyValidationErrors.exception("InvalidParameterException", errors);
}
/** Mirrors the request model's {@code toString}, which AWS embeds in the length-constraint message. */
@@ -3103,10 +3101,7 @@ public class CognitoService implements ResourceProvider {
if (errors.isEmpty()) {
return;
}
- String header = errors.size() == 1
- ? "1 validation error detected: "
- : errors.size() + " validation errors detected: ";
- throw new AwsException("InvalidParameterException", header + String.join("; ", errors), 400);
+ throw validationErrors(errors);
}
/** Mirrors the request model's {@code toString}, which AWS embeds in the length-constraint message. */
diff --git a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
index f38f5c8b1a..f632f44f97 100644
--- a/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/dynamodb/NativeDynamoDbJsonHandler.java
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbTableService.CreateTableRequest;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbTableService.GsiThroughputUpdate;
import io.github.hectorvent.floci.services.dynamodb.NativeDynamoDbTableService.KinesisDestination;
@@ -573,10 +574,7 @@ public class NativeDynamoDbJsonHandler {
+ "Member must satisfy enum value set: [NONE, ALL_OLD]");
}
if (!validationErrors.isEmpty()) {
- int n = validationErrors.size();
- throw new AwsException("ValidationException",
- n + " validation error" + (n > 1 ? "s" : "") + " detected: "
- + String.join("; ", validationErrors), 400);
+ throw SmithyValidationErrors.validationException(validationErrors);
}
DynamoDbExpressionSize.checkWrite(conditionExpression, "ConditionExpression");
DynamoDbAttributeValueValidator.requireNestingWithinLimit(item);
@@ -699,10 +697,7 @@ public class NativeDynamoDbJsonHandler {
+ "Member must satisfy enum value set: [NONE, ALL_OLD]");
}
if (!delValidationErrors.isEmpty()) {
- int n = delValidationErrors.size();
- throw new AwsException("ValidationException",
- n + " validation error" + (n > 1 ? "s" : "") + " detected: "
- + String.join("; ", delValidationErrors), 400);
+ throw SmithyValidationErrors.validationException(delValidationErrors);
}
DynamoDbExpressionSize.checkWrite(conditionExpression, "ConditionExpression");
DynamoDbAttributeValueValidator.requireNestingWithinLimit(exprAttrValues);
@@ -2022,10 +2017,7 @@ public class NativeDynamoDbJsonHandler {
if (validationErrors.isEmpty()) {
return;
}
- int n = validationErrors.size();
- throw new AwsException("ValidationException",
- n + " validation error" + (n > 1 ? "s" : "") + " detected: "
- + String.join("; ", validationErrors), 400);
+ throw SmithyValidationErrors.validationException(validationErrors);
}
private Response transactWriteCanceled(TransactionCanceledException e) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
index dc94f00621..2af732bee8 100644
--- a/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/eventbridge/EventBridgeService.java
@@ -13,6 +13,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
@@ -1320,10 +1321,7 @@ public class EventBridgeService implements ResourceProvider {
+ "Member must have length less than or equal to 4096");
}
if (!violations.isEmpty()) {
- String header = violations.size() == 1
- ? "1 validation error detected: "
- : violations.size() + " validation errors detected: ";
- throw new AwsException("ValidationException", header + String.join("; ", violations), 400);
+ throw SmithyValidationErrors.validationException(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/firehose/S3DestinationValidator.java b/src/main/java/io/github/hectorvent/floci/services/firehose/S3DestinationValidator.java
index 876ded3c15..35bb5b9a81 100644
--- a/src/main/java/io/github/hectorvent/floci/services/firehose/S3DestinationValidator.java
+++ b/src/main/java/io/github/hectorvent/floci/services/firehose/S3DestinationValidator.java
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.services.firehose;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.OpenXJsonSerDe;
import io.github.hectorvent.floci.services.firehose.model.DeliveryStreamDescription.OrcSerDe;
@@ -418,9 +419,6 @@ final class S3DestinationValidator {
}
private static AwsException constraintViolations(List<String> violations) {
- String header = violations.size() == 1
- ? "1 validation error detected: "
- : violations.size() + " validation errors detected: ";
- return new AwsException("ValidationException", header + String.join("; ", violations), 400);
+ return SmithyValidationErrors.validationException(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java
index b7bc1cdb94..a8f31f906b 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iam/IamService.java
@@ -17,6 +17,7 @@ import io.github.hectorvent.floci.core.common.Pem;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ServicePrincipals;
import io.github.hectorvent.floci.core.common.SessionAccountLookup;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.common.SshPublicKeyException;
import io.github.hectorvent.floci.core.common.SshPublicKeys;
import io.github.hectorvent.floci.core.common.Totp;
@@ -3856,18 +3857,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
if (violations.isEmpty()) {
return;
}
- StringBuilder message = new StringBuilder()
- .append(violations.size())
- .append(violations.size() == 1 ? " validation error detected: "
- : " validation errors detected: ");
- for (int i = 0; i < violations.size(); i++) {
- if (i > 0) {
- message.append("; ");
- }
- message.append("Value at 'serviceSpecificCredentialId' failed to satisfy constraint: ")
- .append(violations.get(i));
- }
- throw new AwsException("ValidationError", message.toString(), 400);
+ throw SmithyValidationErrors.validationError(violations.stream()
+ .map(violation -> "Value at 'serviceSpecificCredentialId' failed to satisfy constraint: " + violation)
+ .toList());
}
/** AWS's wording for an id that matches the pattern and no credential. */
diff --git a/src/main/java/io/github/hectorvent/floci/services/iot/IotAuthorizerService.java b/src/main/java/io/github/hectorvent/floci/services/iot/IotAuthorizerService.java
index 295e90f02f..1c1608bb5d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iot/IotAuthorizerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iot/IotAuthorizerService.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iot.model.IotAuthorizer;
@@ -27,7 +28,6 @@ import java.util.Set;
import java.util.TreeMap;
import java.util.function.Consumer;
import java.util.regex.Pattern;
-import java.util.stream.Collectors;
/**
* AWS IoT Core custom authorizers: the records CreateAuthorizer and its peers manage, and the
@@ -392,10 +392,9 @@ public class IotAuthorizerService {
}
private static AwsException constraints(String field, List<String> constraints) {
- return invalid(constraints.size() + " validation error" + (constraints.size() == 1 ? "" : "s") + " detected: "
- + constraints.stream()
- .map(constraint -> "Value at '" + field + "' failed to satisfy constraint: " + constraint)
- .collect(Collectors.joining("; ")));
+ return invalid(SmithyValidationErrors.message(constraints.stream()
+ .map(constraint -> "Value at '" + field + "' failed to satisfy constraint: " + constraint)
+ .toList()));
}
static AwsException invalid(String message) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/iot/IotFleetIndexingService.java b/src/main/java/io/github/hectorvent/floci/services/iot/IotFleetIndexingService.java
index a57fbd0d83..df7ac48420 100644
--- a/src/main/java/io/github/hectorvent/floci/services/iot/IotFleetIndexingService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/iot/IotFleetIndexingService.java
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.MissingNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.Base64Url;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.iot.model.IotIndexingConfiguration;
@@ -456,8 +457,7 @@ public class IotFleetIndexingService {
private static void rejectViolations(List<String> errors) {
if (!errors.isEmpty()) {
- throw invalid(errors.size() + (errors.size() == 1 ? " validation error" : " validation errors")
- + " detected: " + String.join("; ", errors));
+ throw invalid(SmithyValidationErrors.message(errors));
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java b/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java
index 437a9f7b90..0249d0b46e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/kms/KmsJsonHandler.java
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ReservedTags;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.kms.model.KmsAlias;
import io.github.hectorvent.floci.services.kms.model.KmsGrant;
import io.github.hectorvent.floci.services.kms.model.KmsKey;
@@ -713,11 +714,11 @@ public class KmsJsonHandler {
String pattern = "Value '" + keyId + "' at '" + name
+ "' failed to satisfy constraint: Member must satisfy regular expression pattern: ^\\p{ASCII}+$";
if (keyId.isEmpty()) {
- throw new AwsException("ValidationException", "2 validation errors detected: Value '' at '" + name
- + "' failed to satisfy constraint: Member must have length greater than or equal to 1; " + pattern, 400);
+ throw SmithyValidationErrors.validationException(List.of("Value '' at '" + name
+ + "' failed to satisfy constraint: Member must have length greater than or equal to 1", pattern));
}
if (!keyId.chars().allMatch(c -> c < 128)) {
- throw new AwsException("ValidationException", "1 validation error detected: " + pattern, 400);
+ throw SmithyValidationErrors.validationException(pattern);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
index a2b9945938..7301c03514 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/LambdaLayerService.java
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.Base64Url;
import io.github.hectorvent.floci.core.common.Digests;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.lambda.model.LambdaLayerVersion;
import io.github.hectorvent.floci.services.lambda.zip.ZipExtractor;
import io.github.hectorvent.floci.services.s3.S3Service;
@@ -328,9 +329,7 @@ public class LambdaLayerService {
"Member must satisfy enum value set: " + COMPATIBLE_ARCHITECTURES));
}
if (!errors.isEmpty()) {
- throw new AwsException("ValidationException",
- errors.size() + (errors.size() == 1 ? " validation error" : " validation errors")
- + " detected: " + String.join("; ", errors), 400);
+ throw SmithyValidationErrors.validationException(errors);
}
return parsed;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java
index 1cd67b777b..342ebe59e9 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambda/durable/DurableExecutionService.java
@@ -8,6 +8,7 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.Resettable;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend.AccountEntry;
import io.github.hectorvent.floci.core.storage.StorageFactory;
@@ -1121,9 +1122,7 @@ public class DurableExecutionService implements Resettable {
/** AWS reports every invalid member of a request in one ValidationException. */
static AwsException validationError(List<String> violations) {
- String count = violations.size() == 1 ? "1 validation error detected: "
- : violations.size() + " validation errors detected: ";
- return new AwsException("ValidationException", count + String.join("; ", violations), 400);
+ return SmithyValidationErrors.validationException(violations);
}
private static AwsException invalidMarker() {
diff --git a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebValidation.java b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebValidation.java
index 87b444fa2e..57c8768e46 100644
--- a/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebValidation.java
+++ b/src/main/java/io/github/hectorvent/floci/services/lambdaweb/LambdaWebValidation.java
@@ -1,6 +1,6 @@
package io.github.hectorvent.floci.services.lambdaweb;
-import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import java.util.ArrayList;
import java.util.List;
@@ -139,7 +139,6 @@ final class LambdaWebValidation {
if (errors.isEmpty()) {
return;
}
- String head = errors.size() == 1 ? "1 validation error detected: " : errors.size() + " validation errors detected: ";
- throw new AwsException("ValidationException", head + String.join("; ", errors), 400);
+ throw SmithyValidationErrors.validationException(errors);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionImageValidator.java b/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionImageValidator.java
index 72c6eb3a06..81c0997c58 100644
--- a/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionImageValidator.java
+++ b/src/main/java/io/github/hectorvent/floci/services/rekognition/RekognitionImageValidator.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.rekognition;
import com.fasterxml.jackson.databind.JsonNode;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.s3.S3Service;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
@@ -145,9 +146,7 @@ public class RekognitionImageValidator {
}
}
if (!violations.isEmpty()) {
- String count = violations.size() == 1 ? "1 validation error" : violations.size() + " validation errors";
- throw new AwsException("ValidationException",
- count + " detected: " + String.join("; ", violations), 400);
+ throw SmithyValidationErrors.validationException(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java
index 4c59c1d4a4..0dbb0477b1 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountController.java
@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
import io.github.hectorvent.floci.services.ses.model.AccountVdmAttributes;
import jakarta.inject.Inject;
@@ -280,9 +281,9 @@ public class SesAccountController {
JsonNode node = parent.path(field);
if (node.isMissingNode() || node.isNull()) {
if (required) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value null at '" + path
- + "' failed to satisfy constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value null at '" + path
+ + "' failed to satisfy constraint: Member must not be null");
}
return false;
}
@@ -295,9 +296,8 @@ public class SesAccountController {
return false;
}
}
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at '" + path
- + "' failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]",
- 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at '" + path
+ + "' failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java
index f3b5ac2262..713705f940 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesAccountService.java
@@ -200,7 +200,7 @@ public class SesAccountService {
}
}
if (!errors.isEmpty()) {
- throw SmithyValidationErrors.exception("BadRequestException", errors);
+ throw SmithyValidationErrors.badRequest(errors);
}
if (!isValidUrl(websiteUrl)) {
throw new AwsException("BadRequestException", "Url contains invalid format", 400);
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
index 147ce18b9a..10860f81a1 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetController.java
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
import io.github.hectorvent.floci.services.ses.model.ConfigurationSet;
import io.github.hectorvent.floci.services.ses.model.DashboardOptions;
@@ -464,10 +465,10 @@ public class SesConfigurationSetController {
if (format == null) {
format = SIGNATURE_FORMAT_DETACHED;
} else if (!SIGNATURE_FORMAT_DETACHED.equals(format)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at "
+ throw SmithyValidationErrors.badRequest(
+ "Value at "
+ "'messageSecurityOptions.signingScheme.smimeScheme.signatureFormat' failed to "
- + "satisfy constraint: Member must satisfy enum value set: [DETACHED]", 400);
+ + "satisfy constraint: Member must satisfy enum value set: [DETACHED]");
}
return new MessageSecurityOptions(SigningScheme.smime(format));
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java
index 4b347566ca..3c1ecea085 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesConfigurationSetService.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.ArchivingOptions;
@@ -96,12 +97,11 @@ public class SesConfigurationSetService implements SesTaggable {
invalidSuppressionReasonMessage(null), 400);
}
if (!isValidSuppressionReason(reason)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at "
+ throw SmithyValidationErrors.badRequest(
+ "Value at "
+ "'suppressionOptions.suppressedReasons' failed to satisfy "
+ "constraint: Member must satisfy constraint: "
- + "[Member must satisfy enum value set: [BOUNCE, COMPLAINT]]",
- 400);
+ + "[Member must satisfy enum value set: [BOUNCE, COMPLAINT]]");
}
}
}
@@ -230,9 +230,9 @@ public class SesConfigurationSetService implements SesTaggable {
"Domain <" + domain + "> is not verified under this account.", 400);
}
if (httpsPolicy != null && !HTTPS_POLICIES.contains(httpsPolicy)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'httpsPolicy' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [OPTIONAL, REQUIRE, REQUIRE_OPEN_ONLY]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'httpsPolicy' failed to satisfy constraint: "
+ + "Member must satisfy enum value set: [OPTIONAL, REQUIRE, REQUIRE_OPEN_ONLY]");
}
}
@@ -242,9 +242,9 @@ public class SesConfigurationSetService implements SesTaggable {
return;
}
if (options.getTlsPolicy() != null && !TLS_POLICIES.contains(options.getTlsPolicy())) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'tlsPolicy' failed to satisfy constraint: "
- + "Member must satisfy enum value set: [OPTIONAL, REQUIRE]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'tlsPolicy' failed to satisfy constraint: "
+ + "Member must satisfy enum value set: [OPTIONAL, REQUIRE]");
}
// AWS rejects a blank SendingPoolName outright, and a non-existent
// dedicated IP pool (both verified against real AWS 2026-06-17). The
@@ -264,14 +264,14 @@ public class SesConfigurationSetService implements SesTaggable {
if (options.getMaxDeliverySeconds() != null) {
long maxDeliverySeconds = options.getMaxDeliverySeconds();
if (maxDeliverySeconds < 300) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'maxDeliverySeconds' failed to satisfy constraint: "
- + "Member must have value greater than or equal to 300", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'maxDeliverySeconds' failed to satisfy constraint: "
+ + "Member must have value greater than or equal to 300");
}
if (maxDeliverySeconds > 50400) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'maxDeliverySeconds' failed to satisfy constraint: "
- + "Member must have value less than or equal to 50400", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'maxDeliverySeconds' failed to satisfy constraint: "
+ + "Member must have value less than or equal to 50400");
}
}
}
@@ -279,9 +279,9 @@ public class SesConfigurationSetService implements SesTaggable {
void requireVerifiedRedirectDomain(String domain, Predicate<String> verifiedDomainIdentity) {
Objects.requireNonNull(verifiedDomainIdentity, "verifiedDomainIdentity probe is required");
if (domain == null) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'trackingOptions' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'trackingOptions' failed to satisfy constraint: "
+ + "Member must not be null");
}
if (domain.isBlank()) {
throw new AwsException("InvalidTrackingOptions",
@@ -460,16 +460,16 @@ public class SesConfigurationSetService implements SesTaggable {
if (options.getDashboardOptions() != null
&& options.getDashboardOptions().getEngagementMetrics() != null
&& !VDM_FEATURE_STATES.contains(options.getDashboardOptions().getEngagementMetrics())) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'vdmOptions.dashboardOptions.engagementMetrics' "
- + "failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'vdmOptions.dashboardOptions.engagementMetrics' "
+ + "failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]");
}
if (options.getGuardianOptions() != null
&& options.getGuardianOptions().getOptimizedSharedDelivery() != null
&& !VDM_FEATURE_STATES.contains(options.getGuardianOptions().getOptimizedSharedDelivery())) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'vdmOptions.guardianOptions.optimizedSharedDelivery' "
- + "failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'vdmOptions.guardianOptions.optimizedSharedDelivery' "
+ + "failed to satisfy constraint: Member must satisfy enum value set: [ENABLED, DISABLED]");
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java
index 035dbc62fe..6140f1d36e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesContactService.java
@@ -218,8 +218,8 @@ public class SesContactService implements SesTaggable {
// SES V2 surfaces missing/invalid input as Smithy validation errors. Field paths and the
// enum value order are taken verbatim from real AWS.
private static AwsException validationError(String fieldPath, String constraint) {
- return SmithyValidationErrors.exception("BadRequestException",
- List.of("Value at '" + fieldPath + "' failed to satisfy constraint: " + constraint));
+ return SmithyValidationErrors.badRequest(
+ "Value at '" + fieldPath + "' failed to satisfy constraint: " + constraint);
}
private static void validateContactListName(String name) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java
index 3c50add5d2..525ba942d4 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportFilters.java
@@ -92,7 +92,7 @@ final class SesExportFilters {
requireFilterBlock(insights.path("Include"), "include", violations);
requireFilterBlock(insights.path("Exclude"), "exclude", violations);
if (!violations.isEmpty()) {
- throw SmithyValidationErrors.exception("BadRequestException", violations);
+ throw SmithyValidationErrors.badRequest(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java
index 6791c12947..a8b5d5ccdd 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportJobService.java
@@ -143,9 +143,9 @@ public class SesExportJobService implements Resettable {
throw notNull("exportDestination.dataFormat");
}
if (!DATA_FORMATS.contains(dataFormat)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'exportDestination.dataFormat' failed to "
- + "satisfy constraint: Member must satisfy enum value set: [CSV, JSON]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'exportDestination.dataFormat' failed to "
+ + "satisfy constraint: Member must satisfy enum value set: [CSV, JSON]");
}
// Probe-confirmed order: the data source and the destination's own constraints are checked
// first, then the refusal of a caller-chosen destination, then the VDM gate.
@@ -388,16 +388,16 @@ public class SesExportJobService implements Resettable {
/** Newest first, as SES lists them; the paged list resumes on the same order. */
public List<ExportJob> listExportJobs(String region, String sourceType, String jobStatus) {
if (sourceType != null && !SOURCE_TYPES.contains(sourceType)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'exportSourceType' failed to satisfy "
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'exportSourceType' failed to satisfy "
+ "constraint: Member must satisfy enum value set: "
- + "[METRICS_DATA, MESSAGE_INSIGHTS]", 400);
+ + "[METRICS_DATA, MESSAGE_INSIGHTS]");
}
if (jobStatus != null && !JOB_STATUSES.contains(jobStatus)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'jobStatus' failed to satisfy "
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'jobStatus' failed to satisfy "
+ "constraint: Member must satisfy enum value set: "
- + "[CREATED, PROCESSING, COMPLETED, FAILED, CANCELLED]", 400);
+ + "[CREATED, PROCESSING, COMPLETED, FAILED, CANCELLED]");
}
return exportJobStore.scan(k -> k.startsWith(keyPrefix(region))).stream()
.filter(job -> sourceType == null || sourceType.equals(job.getExportSourceType()))
@@ -540,8 +540,8 @@ public class SesExportJobService implements Resettable {
}
private static AwsException notNull(String member) {
- return SmithyValidationErrors.exception("BadRequestException",
- List.of("Value at '" + member + "' failed to satisfy constraint: Member must not be null"));
+ return SmithyValidationErrors.badRequest(
+ "Value at '" + member + "' failed to satisfy constraint: Member must not be null");
}
/**
@@ -556,21 +556,21 @@ public class SesExportJobService implements Resettable {
return;
}
if (maxResults < 1 || maxResults > MAX_RESULTS) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at "
+ throw SmithyValidationErrors.badRequest(
+ "Value at "
+ "'exportDataSource.messageInsightsDataSource.maxResults' failed to "
+ "satisfy constraint: Member must be between 1 and " + MAX_RESULTS
- + ", inclusive", 400);
+ + ", inclusive");
}
}
private static Instant requireDate(JsonNode source, String field) {
Instant value = date(source, field);
if (value == null) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at '" + field.substring(0, 1).toLowerCase(Locale.ROOT)
+ throw SmithyValidationErrors.badRequest(
+ "Value at '" + field.substring(0, 1).toLowerCase(Locale.ROOT)
+ field.substring(1) + "' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ + "Member must not be null");
}
return value;
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java
index f47ecc33fa..b5ca3a063a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesExportMetrics.java
@@ -70,7 +70,7 @@ final class SesExportMetrics {
}
validateMetrics(metrics.path("Metrics"), violations);
if (!violations.isEmpty()) {
- throw SmithyValidationErrors.exception("BadRequestException", violations);
+ throw SmithyValidationErrors.badRequest(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java
index cea7f2c7f5..9735fb0c2e 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityCertificateService.java
@@ -349,7 +349,7 @@ public class SesIdentityCertificateService {
if (violations.isEmpty()) {
return;
}
- throw SmithyValidationErrors.exception("BadRequestException", violations);
+ throw SmithyValidationErrors.badRequest(violations);
}
private static AwsException badRequest(String message) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java
index fa8fcc0308..6050c1f31d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityController.java
@@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.ses.model.Identity;
import io.github.hectorvent.floci.services.ses.model.Tag;
import jakarta.inject.Inject;
@@ -284,9 +285,9 @@ public class SesIdentityController {
JsonNode policyNode = request.path("Policy");
if (policyNode.isMissingNode() || policyNode.isNull()) {
// Verified against AWS: a missing/null required member is a Smithy validation error.
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'policy' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'policy' failed to satisfy constraint: "
+ + "Member must not be null");
}
if (!policyNode.isTextual()) {
// Policy is a String; AWS rejects a non-string with an empty-bodied 400. Don't coerce
@@ -561,9 +562,9 @@ public class SesIdentityController {
if ("USE_DEFAULT_VALUE".equals(v2)) {
return "UseDefaultValue";
}
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'behaviorOnMxFailure' failed to satisfy "
- + "constraint: Member must satisfy enum value set: [REJECT_MESSAGE, USE_DEFAULT_VALUE]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'behaviorOnMxFailure' failed to satisfy "
+ + "constraint: Member must satisfy enum value set: [REJECT_MESSAGE, USE_DEFAULT_VALUE]");
}
private ObjectNode buildDkimAttributes(Identity identity, String region) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java
index 67b00319c6..00fb7df524 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesIdentityService.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.route53.Route53Service;
@@ -350,9 +351,9 @@ public class SesIdentityService implements SesTaggable {
if (behaviorOnMxFailure != null) {
if (!"UseDefaultValue".equals(behaviorOnMxFailure)
&& !"RejectMessage".equals(behaviorOnMxFailure)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'behaviorOnMXFailure' failed to satisfy "
- + "constraint: Member must satisfy enum value set: [RejectMessage, UseDefaultValue]", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'behaviorOnMXFailure' failed to satisfy "
+ + "constraint: Member must satisfy enum value set: [RejectMessage, UseDefaultValue]");
}
normalizedBehavior = behaviorOnMxFailure;
}
@@ -468,10 +469,10 @@ public class SesIdentityService implements SesTaggable {
"NotificationType is required.", 400);
}
if (!NOTIFICATION_TYPES.contains(notificationType)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'notificationType' failed to satisfy "
+ throw SmithyValidationErrors.validationError(
+ "Value at 'notificationType' failed to satisfy "
+ "constraint: Member must satisfy enum value set: "
- + NOTIFICATION_TYPES, 400);
+ + NOTIFICATION_TYPES);
}
synchronized (identityCreationLock) {
Identity identity = identityStore.get(identityKey(region, identityValue))
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java
index 83e83f7f09..ea92c4fbb0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesImportJobService.java
@@ -470,8 +470,8 @@ public class SesImportJobService implements Resettable {
}
private static AwsException validationError(String path, String constraint) {
- return SmithyValidationErrors.exception("BadRequestException",
- List.of("Value at '" + path + "' failed to satisfy constraint: " + constraint));
+ return SmithyValidationErrors.badRequest(
+ "Value at '" + path + "' failed to satisfy constraint: " + constraint);
}
static String key(String region, String jobId) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java
index c361e82fe3..dfac2f5d48 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesListPaging.java
@@ -113,7 +113,7 @@ public enum SesListPaging {
* default could not be measured and is taken to be the bound.
*/
V2_LIST_EMAIL_IDENTITY_CERTIFICATES(Namespace.IDENTITY_CERTIFICATE, 1000, 1000,
- size -> badRequest("1 validation error detected: Value '" + size + "' at 'pageSize' failed to "
+ size -> SmithyValidationErrors.badRequest("Value '" + size + "' at 'pageSize' failed to "
+ "satisfy constraint: Member must have value "
+ (size < 1 ? "greater than or equal to 1" : "less than or equal to 1000")),
token -> badRequest("Invalid NextToken."),
@@ -179,19 +179,19 @@ public enum SesListPaging {
}
static AwsException pageSizeError(int pageSize) {
- return SmithyValidationErrors.exception("BadRequestException", List.of(pageSizeViolation(pageSize)));
+ return SmithyValidationErrors.badRequest(pageSizeViolation(pageSize));
}
static AwsException tokenError(String token) {
if (token.isEmpty()) {
- return SmithyValidationErrors.exception("BadRequestException", List.of(EMPTY_TOKEN));
+ return SmithyValidationErrors.badRequest(EMPTY_TOKEN);
}
return badRequest("Invalid Next Token");
}
/** SES lists the token before the page size. */
static AwsException bothError(int pageSize) {
- return SmithyValidationErrors.exception("BadRequestException",
+ return SmithyValidationErrors.badRequest(
List.of(EMPTY_TOKEN, pageSizeViolation(pageSize)));
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java
index 58e3159f12..ca47dbb56a 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesMetricsController.java
@@ -371,6 +371,6 @@ public class SesMetricsController {
}
private static AwsException aggregated(List<String> violations) {
- return SmithyValidationErrors.exception("BadRequestException", violations);
+ return SmithyValidationErrors.badRequest(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesPolicyService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesPolicyService.java
index 35b74f4bc8..f2e8096822 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesPolicyService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesPolicyService.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import jakarta.enterprise.context.ApplicationScoped;
@@ -172,9 +173,9 @@ public class SesPolicyService {
throw new AwsException("InvalidParameterValue", "PolicyName is required.", 400);
}
if (policyName.length() > 64) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'policyName' failed to satisfy constraint: "
- + "Member must have length less than or equal to 64", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'policyName' failed to satisfy constraint: "
+ + "Member must have length less than or equal to 64");
}
if (!POLICY_NAME_CHARS.matcher(policyName).matches()) {
throw new AwsException("InvalidParameterValue",
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java
index d1badcd7d0..10071f1d09 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesQueryHandler.java
@@ -7,6 +7,7 @@ import io.github.hectorvent.floci.core.common.AwsNamespaces;
import io.github.hectorvent.floci.core.common.AwsQueryResponse;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.common.XmlBuilder;
import io.github.hectorvent.floci.services.ses.address.SesAddressSyntax;
import io.github.hectorvent.floci.services.ses.model.BulkEmailEntry;
@@ -1041,10 +1042,9 @@ public class SesQueryHandler {
// here so an invalid enum value yields the v1 ValidationError AWS returns rather than the
// shared service's v2-style BadRequestException. Message verified against real AWS.
if (tlsPolicy != null && !"Require".equals(tlsPolicy) && !"Optional".equals(tlsPolicy)) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'deliveryOptions.tlsPolicy' failed to "
- + "satisfy constraint: Member must satisfy enum value set: [Optional, Require]",
- 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'deliveryOptions.tlsPolicy' failed to "
+ + "satisfy constraint: Member must satisfy enum value set: [Optional, Require]");
}
// Mirror the V2 path: an all-null DeliveryOptions clears the block rather than
// persisting an empty object. Normalize the value to the V2 canonical REQUIRE/OPTIONAL
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java
index b7351a94af..87769f34c0 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesReceiptRuleService.java
@@ -484,7 +484,7 @@ public class SesReceiptRuleService {
if (violations.isEmpty()) {
return;
}
- throw SmithyValidationErrors.exception("ValidationError", violations);
+ throw SmithyValidationErrors.validationError(violations);
}
/**
@@ -732,9 +732,9 @@ public class SesReceiptRuleService {
if (filterName == null) {
// Probed: an absent FilterName is the one case the wire rejects; deleting a missing
// or malformed name succeeds without error.
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'filterName' failed to satisfy "
- + "constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'filterName' failed to satisfy "
+ + "constraint: Member must not be null");
}
receiptFilterStore.delete(receiptFilterKey(region, filterName));
LOG.infov("Deleted SES receipt filter: {0} in region {1}", filterName, region);
@@ -751,8 +751,8 @@ public class SesReceiptRuleService {
*/
private static void validateFilterShape(ReceiptFilter filter) {
if (filter == null) {
- throw new AwsException("ValidationError",
- "1 validation error detected: " + notNullViolation("filter"), 400);
+ throw SmithyValidationErrors.validationError(
+ notNullViolation("filter"));
}
List<String> violations = new ArrayList<>();
if (filter.getName() == null) {
@@ -773,7 +773,7 @@ public class SesReceiptRuleService {
}
}
if (!violations.isEmpty()) {
- throw SmithyValidationErrors.exception("ValidationError", violations);
+ throw SmithyValidationErrors.validationError(violations);
}
}
@@ -900,9 +900,9 @@ public class SesReceiptRuleService {
throw new AwsException("InvalidParameterValue", "RuleSetName is required.", 400);
}
if (!RULE_SET_NAME_CHARS.matcher(name).matches()) {
- throw new AwsException("ValidationError",
- "1 validation error detected: Value at 'ruleSetName' failed to satisfy constraint: "
- + "Member must satisfy regular expression pattern: ^[a-zA-Z0-9_.-]+$", 400);
+ throw SmithyValidationErrors.validationError(
+ "Value at 'ruleSetName' failed to satisfy constraint: "
+ + "Member must satisfy regular expression pattern: ^[a-zA-Z0-9_.-]+$");
}
requireValidRuleSetName(name);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java
index 450003b8a8..f92100e618 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSendController.java
@@ -588,8 +588,8 @@ public class SesSendController {
private static AwsException constraintViolation(String value, String path, String constraint) {
String subject = value == null ? "Value" : "Value '" + value + "'";
- return SmithyValidationErrors.exception("BadRequestException",
- List.of(subject + " at '" + path + "' failed to satisfy constraint: " + constraint));
+ return SmithyValidationErrors.badRequest(
+ subject + " at '" + path + "' failed to satisfy constraint: " + constraint);
}
private static AwsException missingHeaderMember(String location, int index, String member) {
@@ -614,7 +614,7 @@ public class SesSendController {
violations.add(trackingViolation("openTrackingEnabled"));
}
if (!violations.isEmpty()) {
- throw SmithyValidationErrors.exception("BadRequestException", violations);
+ throw SmithyValidationErrors.badRequest(violations);
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java
index 891e347a4d..a111b04563 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesSuppressionService.java
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.ses;
import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.AccountSuppressionAttributes;
@@ -339,9 +340,9 @@ public class SesSuppressionService {
String constraint = nested
? "Member must satisfy constraint: [Member must satisfy enum value set: [BOUNCE, COMPLAINT]]"
: "Member must satisfy enum value set: [BOUNCE, COMPLAINT]";
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at '" + fieldName + "' failed to satisfy constraint: "
- + constraint, 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at '" + fieldName + "' failed to satisfy constraint: "
+ + constraint);
}
}
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java
index 360374a5d6..e5a84a05bc 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTags.java
@@ -85,7 +85,7 @@ final class SesTags {
}
}
if (!lengthErrors.isEmpty()) {
- throw SmithyValidationErrors.exception("BadRequestException", lengthErrors);
+ throw SmithyValidationErrors.badRequest(lengthErrors);
}
// An empty key is rejected with an empty body, matching AWS.
for (Tag tag : tags) {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java
index bcf867d6ea..628011d46d 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesTenantService.java
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.type.TypeReference;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.ses.model.Tag;
@@ -378,9 +379,9 @@ public class SesTenantService implements SesTaggable {
*/
public static AssociationResource parseResourceArn(String resourceArn, String accountId, String region) {
if (resourceArn == null) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'resourceArn' failed to satisfy constraint: "
- + "Member must not be null", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'resourceArn' failed to satisfy constraint: "
+ + "Member must not be null");
}
String[] parts = resourceArn.split(":", 6);
if (parts.length < 6 || !"arn".equals(parts[0])) {
@@ -613,9 +614,9 @@ public class SesTenantService implements SesTaggable {
}
if (suppressionScope != null && !"TENANT".equals(suppressionScope)
&& !"ACCOUNT".equals(suppressionScope)) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'suppressionScope' failed to satisfy "
- + "constraint: Member must satisfy enum value set: [TENANT, ACCOUNT]", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'suppressionScope' failed to satisfy "
+ + "constraint: Member must satisfy enum value set: [TENANT, ACCOUNT]");
}
if (suppressedReasons != null) {
Set<String> seen = new HashSet<>();
@@ -649,17 +650,17 @@ public class SesTenantService implements SesTaggable {
private static void validateTenantName(String name, boolean createTenantSmithyVariants) {
if (name == null) {
if (createTenantSmithyVariants) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'tenantName' failed to satisfy "
- + "constraint: Member must not be null", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'tenantName' failed to satisfy "
+ + "constraint: Member must not be null");
}
throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);
}
if (name.isEmpty()) {
if (createTenantSmithyVariants) {
- throw new AwsException("BadRequestException",
- "1 validation error detected: Value at 'tenantName' failed to satisfy "
- + "constraint: Member must have length greater than or equal to 1", 400);
+ throw SmithyValidationErrors.badRequest(
+ "Value at 'tenantName' failed to satisfy "
+ + "constraint: Member must have length greater than or equal to 1");
}
throw new AwsException("BadRequestException", "TenantName cannot be empty", 400);
}
diff --git a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
index a6f0491d28..74e857bf8c 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ses/SesV2Json.java
@@ -5,6 +5,7 @@ import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsException;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.services.ses.model.Tag;
import java.time.Instant;
@@ -198,14 +199,14 @@ final class SesV2Json {
return Map.of();
}
if (!keys.containsAll(filter.keySet())) {
- throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' "
+ throw SmithyValidationErrors.badRequest( "Value at 'filter' "
+ "failed to satisfy constraint: Map keys must satisfy constraint: "
- + "[Member must satisfy enum value set: [" + String.join(", ", keys) + "]]", 400);
+ + "[Member must satisfy enum value set: [" + String.join(", ", keys) + "]]");
}
if (filter.containsValue("")) {
- throw new AwsException("BadRequestException", "1 validation error detected: Value at 'filter' "
+ throw SmithyValidationErrors.badRequest( "Value at 'filter' "
+ "failed to satisfy constraint: Map value must satisfy constraint: "
- + "[Member must have length greater than or equal to 1]", 400);
+ + "[Member must have length greater than or equal to 1]");
}
Map<String, String> values = new LinkedHashMap<>();
filter.forEach((key, value) -> {
diff --git a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java
index b39eb2d31a..34c53fcc80 100644
--- a/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java
+++ b/src/main/java/io/github/hectorvent/floci/services/ssm/SsmService.java
@@ -10,6 +10,7 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.DeadlineCharSequence;
import io.github.hectorvent.floci.core.common.RegionResolver;
+import io.github.hectorvent.floci.core.common.SmithyValidationErrors;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
@@ -871,10 +872,7 @@ public class SsmService implements ResourceProvider {
}
static AwsException validationErrors(List<String> violations) {
- String count = violations.size() == 1
- ? "1 validation error detected: "
- : violations.size() + " validation errors detected: ";
- return new AwsException("ValidationException", count + String.join("; ", violations), 400);
+ return SmithyValidationErrors.validationException(violations);
}
private static boolean isValidLabel(String label) {
diff --git a/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java b/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java
index b9983489d7..d6ce366076 100644
--- a/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java
+++ b/src/test/java/io/github/hectorvent/floci/core/common/SmithyValidationErrorsTest.java
@@ -29,6 +29,22 @@ class SmithyValidationErrorsTest {
assertEquals(400, e.getHttpStatus());
}
+ @Test
+ void namedFactories_carryTheirProtocolsCode() {
+ assertEquals("ValidationException", SmithyValidationErrors.validationException(List.of("v")).getErrorCode());
+ assertEquals("ValidationError", SmithyValidationErrors.validationError(List.of("v")).getErrorCode());
+ assertEquals("BadRequestException", SmithyValidationErrors.badRequest(List.of("v")).getErrorCode());
+ }
+
+ @Test
+ void stringOverloads_reportOneViolation() {
+ String expected = "1 validation error detected: v";
+ assertEquals(expected, SmithyValidationErrors.badRequest("v").getMessage());
+ assertEquals(expected, SmithyValidationErrors.validationError("v").getMessage());
+ assertEquals(expected, SmithyValidationErrors.validationException("v").getMessage());
+ assertEquals(expected, SmithyValidationErrors.exception("InvalidParameterException", "v").getMessage());
+ }
+
@Test
void noViolations_isAProgrammingError() {
assertThrows(IllegalArgumentException.class, () -> SmithyValidationErrors.message(List.of()));