From eb84539a677554f124a176eb9a01335475fbc82c Mon Sep 17 00:00:00 2001 From: XuJian <265865031+xujiantop-crypto@users.noreply.github.com> Date: Sat, 17 Oct 2026 05:52:27 +0800 Subject: [PATCH] fix(iot): return ConflictException for shadow version mismatch (#5814) * fix(iot): return ConflictException for shadow version mismatch * fix(iot): match AWS shadow version conflict message * test(iot): expect modeled shadow conflict in Python SDK --- .../sdk-test-python/tests/test_iot.py | 3 +- .../floci/services/iot/IotService.java | 2 +- .../services/iot/IotDataIntegrationTest.java | 38 ++++++++++++++++++- 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/compatibility-tests/sdk-test-python/tests/test_iot.py b/compatibility-tests/sdk-test-python/tests/test_iot.py index 5f58566cb1..94f122b1b6 100644 --- a/compatibility-tests/sdk-test-python/tests/test_iot.py +++ b/compatibility-tests/sdk-test-python/tests/test_iot.py @@ -327,7 +327,8 @@ def test_iot_data_retained_messages_and_shadow_conflicts(iot_data_client, unique ) raise AssertionError("stale shadow update should fail") except ClientError as exc: - assert exc.response["Error"]["Code"] == "VersionConflictException" + assert exc.response["Error"]["Code"] == "ConflictException" + assert exc.response["Error"]["Message"] == "Version conflict" def test_topic_rule_crud_and_sqs_action(iot_client, iot_data_client, sqs_client, unique_name): diff --git a/src/main/java/io/github/hectorvent/floci/services/iot/IotService.java b/src/main/java/io/github/hectorvent/floci/services/iot/IotService.java index 53c5c1dd03..06f99873f7 100644 --- a/src/main/java/io/github/hectorvent/floci/services/iot/IotService.java +++ b/src/main/java/io/github/hectorvent/floci/services/iot/IotService.java @@ -865,7 +865,7 @@ public class IotService { ObjectNode document = existing == null ? objectMapper.createObjectNode() : (ObjectNode) readJson(existing.getDocument()).deepCopy(); long currentVersion = existing == null ? 0 : existing.getVersion(); if (request.hasNonNull("version") && request.path("version").asLong() != currentVersion) { - throw new AwsException("VersionConflictException", "Shadow version does not match requested version", 409); + throw new AwsException("ConflictException", "Version conflict", 409); } ObjectNode state = document.withObject("/state"); JsonNode requestState = request.path("state"); diff --git a/src/test/java/io/github/hectorvent/floci/services/iot/IotDataIntegrationTest.java b/src/test/java/io/github/hectorvent/floci/services/iot/IotDataIntegrationTest.java index 362709c99e..032def6059 100644 --- a/src/test/java/io/github/hectorvent/floci/services/iot/IotDataIntegrationTest.java +++ b/src/test/java/io/github/hectorvent/floci/services/iot/IotDataIntegrationTest.java @@ -193,7 +193,9 @@ class IotDataIntegrationTest { .post("/things/mvp1-shadow/shadow") .then() .statusCode(409) - .body("__type", equalTo("VersionConflictException")); + .header("x-amzn-ErrorType", equalTo("ConflictException")) + .body("__type", equalTo("ConflictException")) + .body("message", equalTo("Version conflict")); given() .contentType("application/json") @@ -205,4 +207,38 @@ class IotDataIntegrationTest { .body("state.desired", nullValue()) .body("version", equalTo(3)); } + + @Test + void namedShadowVersionConflictUsesIotDataErrorCode() { + given() + .contentType("application/json") + .queryParam("name", "settings") + .body("{\"state\":{\"desired\":{\"mode\":\"auto\"}}}") + .when() + .post("/things/mvp1-versioned-named/shadow") + .then() + .statusCode(200) + .body("version", equalTo(1)); + + given() + .contentType("application/json") + .queryParam("name", "settings") + .body("{\"version\":0,\"state\":{\"desired\":{\"mode\":\"manual\"}}}") + .when() + .post("/things/mvp1-versioned-named/shadow") + .then() + .statusCode(409) + .header("x-amzn-ErrorType", equalTo("ConflictException")) + .body("__type", equalTo("ConflictException")) + .body("message", equalTo("Version conflict")); + + given() + .queryParam("name", "settings") + .when() + .get("/things/mvp1-versioned-named/shadow") + .then() + .statusCode(200) + .body("version", equalTo(1)) + .body("state.desired.mode", equalTo("auto")); + } }