From 36345c8985f06cf574846e7e13e76101bc57ec9f Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Fri, 20 Nov 2026 13:08:28 +0000 Subject: [PATCH 1/9] fix(server): write __type first in an error body ExtendDB wrote the members of an error body in name order, so CancellationReasons, Item and Message came before __type. Amazon DynamoDB writes __type first, then CancellationReasons or Item, then the message. The order was measured in us-east-1 on 20 Nov 2026 from the raw response bytes, and each request went out twice. A TransactWriteItems and an ExecuteTransaction cancelled by a failed condition write __type, CancellationReasons, Message. A PutItem whose condition fails with ReturnValuesOnConditionCheckFailure ALL_OLD writes __type, Item, message. An IdempotentParameterMismatchException and a SerializationException write __type, Message. error_response now writes the members in that order. Each cancellation reason keeps its members in name order, which is the order DynamoDB writes. Fixes #1222. --- crates/server/src/response.rs | 48 +++++++------ crates/server/src/response_tests.rs | 103 +++++++++++++++++++--------- tests/test_error_message_key.py | 16 +++-- 3 files changed, 106 insertions(+), 61 deletions(-) diff --git a/crates/server/src/response.rs b/crates/server/src/response.rs index 714e49a05..7ed10d927 100755 --- a/crates/server/src/response.rs +++ b/crates/server/src/response.rs @@ -6,6 +6,7 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; use extenddb_core::error::DynamoDbError; +use serde::ser::{SerializeMap as _, Serializer as _}; use serde_json::Value; #[cfg(test)] @@ -41,26 +42,7 @@ pub(crate) fn success_response(body: &Value, request_id: &str) -> Response { /// key [`message_key`] picks. REQ-ERR-003: Omit the message field when empty /// (real `DynamoDB` behavior, verified 2026-05-04). pub(crate) fn error_response(error: &DynamoDbError, request_id: &str) -> Response { - // Fix #14: Use full_error_type() which includes the prefix - let mut body = serde_json::json!({ - "__type": error.full_error_type(), - }); - // Only include message field when non-empty (real DynamoDB omits it for - // UnknownOperationException and other errors with no message). - let msg = error.message(); - if !msg.is_empty() { - body[message_key(error)] = serde_json::Value::String(msg.to_owned()); - } - // TransactionCanceledException includes per-item CancellationReasons - if let Some(reasons) = error.cancellation_reasons() { - body["CancellationReasons"] = serde_json::to_value(reasons).unwrap_or_default(); - } - // ConditionalCheckFailedException includes the old item when requested - if let Some(item) = error.condition_check_item() { - body["Item"] = serde_json::to_value(item).unwrap_or_default(); - } - let body_bytes = - serde_json::to_vec(&body).unwrap_or_else(|_| SERIALIZATION_FAILURE_BODY.to_vec()); + let body_bytes = error_body(error).unwrap_or_else(|_| SERIALIZATION_FAILURE_BODY.to_vec()); let crc = crc32fast::hash(&body_bytes); let status = StatusCode::from_u16(error.status_code()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR); @@ -77,6 +59,32 @@ pub(crate) fn error_response(error: &DynamoDbError, request_id: &str) -> Respons .into_response() } +/// The body of `error`, with its members in the order `DynamoDB` writes them +/// (us-east-1, raw bodies, 2026-11-20): `__type` first, then the +/// `CancellationReasons` of a `TransactionCanceledException` or the `Item` of +/// a `ConditionalCheckFailedException`, then the message. +fn error_body(error: &DynamoDbError) -> serde_json::Result> { + let mut bytes = Vec::new(); + let mut serializer = serde_json::Serializer::new(&mut bytes); + let mut body = serializer.serialize_map(None)?; + body.serialize_entry("__type", &error.full_error_type())?; + // Through a `Value`, each reason writes its members in name order, as + // `DynamoDB` does: `Code`, `Item`, `Message`. + if let Some(reasons) = error.cancellation_reasons() { + let reasons = serde_json::to_value(reasons).unwrap_or_default(); + body.serialize_entry("CancellationReasons", &reasons)?; + } + if let Some(item) = error.condition_check_item() { + body.serialize_entry("Item", item)?; + } + let msg = error.message(); + if !msg.is_empty() { + body.serialize_entry(message_key(error), msg)?; + } + body.end()?; + Ok(bytes) +} + /// The key that carries the error message: `Message` on the errors matched /// below, as `DynamoDB` sends them (us-east-1, raw bodies, 2026-10-29 to /// 2026-11-20), `message` on the others. `DynamoDB` also sends `Message` on diff --git a/crates/server/src/response_tests.rs b/crates/server/src/response_tests.rs index cb71f310b..75075ebf6 100644 --- a/crates/server/src/response_tests.rs +++ b/crates/server/src/response_tests.rs @@ -4,26 +4,42 @@ //! Tests of the error bodies [`super::error_response`] sends. use extenddb_core::error::DynamoDbError; -use extenddb_core::types::CancellationReason; +use extenddb_core::types::{AttributeValue, CancellationReason, Item}; +use serde::de::{Deserializer as _, IgnoredAny, MapAccess, Visitor}; use super::error_response; -/// The top-level keys of the body `error_response` sends for `error`. -async fn body_keys(error: &DynamoDbError) -> Vec { +/// The top-level member names of the body `error_response` sends for +/// `error`, in the order of the bytes. +async fn body_members(error: &DynamoDbError) -> Vec { + struct Names; + impl<'de> Visitor<'de> for Names { + type Value = Vec; + fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str("an object") + } + fn visit_map>(self, mut map: A) -> Result { + let mut names = Vec::new(); + while let Some((name, IgnoredAny)) = map.next_entry::()? { + names.push(name); + } + Ok(names) + } + } let response = error_response(error, "request-1"); let bytes = axum::body::to_bytes(response.into_body(), usize::MAX) .await .expect("body"); - let body: serde_json::Value = serde_json::from_slice(&bytes).expect("json body"); - let mut keys: Vec = body.as_object().expect("object").keys().cloned().collect(); - keys.sort_unstable(); - keys + serde_json::Deserializer::from_slice(&bytes) + .deserialize_map(Names) + .expect("json object") } -/// The errors measured with `Message` carry it under that key, as the -/// service sends them; the errors measured with `message` keep it. +/// Each body writes `__type` first and the other members in the order the +/// service writes them, with the message under the key the service uses for +/// that error (us-east-1, raw bodies, 2026-10-29 to 2026-11-20). #[tokio::test] -async fn the_message_key_follows_the_service_per_error() { +async fn the_members_follow_the_service_per_error() { let cancelled = DynamoDbError::TransactionCanceledException { message: "Transaction cancelled, please refer cancellation reasons for specific \ reasons [ConditionalCheckFailed]" @@ -34,30 +50,49 @@ async fn the_message_key_follows_the_service_per_error() { item: None, }], }; - assert_eq!( - body_keys(&cancelled).await, - ["CancellationReasons", "Message", "__type"] - ); - let mismatch = DynamoDbError::IdempotentParameterMismatchException( - "Specified idempotent token was used with different request parameters within \ - the idempotency window" - .to_owned(), - ); - assert_eq!(body_keys(&mismatch).await, ["Message", "__type"]); - let serialization = DynamoDbError::SerializationException( - "STRING_VALUE cannot be converted to Integer".to_owned(), - ); - assert_eq!(body_keys(&serialization).await, ["Message", "__type"]); - let empty = DynamoDbError::SerializationException(String::new()); - assert_eq!(body_keys(&empty).await, ["__type"]); - for other in [ - DynamoDbError::ValidationException("One or more parameter values were invalid".into()), - DynamoDbError::ConditionalCheckFailedException( - "The conditional request failed".into(), - None, + let old_item = Item::from([("pk".to_owned(), AttributeValue::S("e1222".to_owned()))]); + let failed = "The conditional request failed"; + let rows: [(DynamoDbError, &[&str]); 7] = [ + (cancelled, &["__type", "CancellationReasons", "Message"]), + ( + DynamoDbError::ConditionalCheckFailedException(failed.into(), Some(old_item)), + &["__type", "Item", "message"], + ), + ( + DynamoDbError::ConditionalCheckFailedException(failed.into(), None), + &["__type", "message"], + ), + ( + DynamoDbError::IdempotentParameterMismatchException( + "Specified idempotent token was used with different request parameters \ + within the idempotency window" + .to_owned(), + ), + &["__type", "Message"], + ), + ( + DynamoDbError::SerializationException( + "STRING_VALUE cannot be converted to Integer".to_owned(), + ), + &["__type", "Message"], + ), + ( + DynamoDbError::SerializationException(String::new()), + &["__type"], + ), + ( + DynamoDbError::ValidationException("One or more parameter values were invalid".into()), + &["__type", "message"], ), - DynamoDbError::TransactionConflictException("Transaction is ongoing".into()), - ] { - assert_eq!(body_keys(&other).await, ["__type", "message"], "{other:?}"); + ]; + let mut got = Vec::new(); + let mut want: Vec<(&str, Vec)> = Vec::new(); + for (error, members) in &rows { + got.push((error.error_type(), body_members(error).await)); + want.push(( + error.error_type(), + members.iter().map(ToString::to_string).collect(), + )); } + assert_eq!(got, want); } diff --git a/tests/test_error_message_key.py b/tests/test_error_message_key.py index 9f3ba6a1a..dddaf8982 100644 --- a/tests/test_error_message_key.py +++ b/tests/test_error_message_key.py @@ -9,7 +9,9 @@ (raw bodies measured in us-east-1 on 2026-10-29, 2026-11-03 and 2026-11-19). It also sends ``Message`` on TransactionInProgressException, AccessDeniedException and SerializationException. REQ-ERR-002 in -docs/design/01-requirements.md lists the errors measured. botocore reads +docs/design/01-requirements.md lists the errors measured. DynamoDB writes +``__type`` first in each of these bodies (2026-11-20), so the tests read the +keys in the order of the raw bytes. botocore reads either key, so these tests read the raw body from botocore's ``before-parse`` event before it normalizes it. @@ -40,8 +42,8 @@ def hash_table(dynamodb_client): def _error_code_and_keys(client, operation: str, call) -> tuple[str, list[str]]: - """Run ``call``, which must fail, and return the error code and the sorted - top-level keys of the raw response body.""" + """Run ``call``, which must fail, and return the error code and the + top-level keys of the raw response body, in the order of the bytes.""" raw: list[bytes] = [] def capture(response_dict, **_kwargs): @@ -54,7 +56,7 @@ def capture(response_dict, **_kwargs): call() finally: client.meta.events.unregister(event, capture) - return exc_info.value.response["Error"]["Code"], sorted(json.loads(raw[-1])) + return exc_info.value.response["Error"]["Code"], list(json.loads(raw[-1])) def test_transaction_canceled_carries_message_under_capital_m(dynamodb_client, hash_table): @@ -74,7 +76,7 @@ def test_transaction_canceled_carries_message_under_capital_m(dynamodb_client, h ), ) assert code == "TransactionCanceledException" - assert keys == ["CancellationReasons", "Message", "__type"] + assert keys == ["__type", "CancellationReasons", "Message"] def test_idempotent_parameter_mismatch_carries_message_under_capital_m( @@ -94,7 +96,7 @@ def put(value: str): put("first") code, keys = _error_code_and_keys(dynamodb_client, "TransactWriteItems", lambda: put("second")) assert code == "IdempotentParameterMismatchException" - assert keys == ["Message", "__type"] + assert keys == ["__type", "Message"] # Raw bodies measured in us-east-1 on 2026-11-20, each request sent twice, @@ -130,7 +132,7 @@ def test_serialization_error_carries_message_under_capital_m( call = getattr(client, xform_name(operation)) code, keys = _error_code_and_keys(client, operation, lambda: call(**params)) assert code == "SerializationException" - assert keys == ["Message", "__type"] + assert keys == ["__type", "Message"] def test_conditional_check_failed_carries_message_under_lower_case(dynamodb_client, hash_table): From 62ca68e66d61669017a50dd3edb9906129d50847 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:27:23 +0000 Subject: [PATCH 2/9] fix(core): write the error body once, for the server and the wasm build error_document in crates/core/src/error/mod.rs now writes the error body and returns its bytes. It writes the members in the order DynamoDB writes them: __type, then CancellationReasons or Item, then the message. It replaces the two writers of the body on this branch. The server sent the bytes of error_body. The WebAssembly adapter sent the serde_json::Value that error_document built. error_response in the server sends the bytes. Engine::submit and Engine::non_string_argument in the WebAssembly adapter return them as a String. The WebAssembly answers change order too. That build has no MongoDB backend, so serde_json wrote the members of the Value in name order, for example Message before __type on a SerializationException. The core tests of error_document parse the bytes. --- crates/core/src/error/mod.rs | 59 ++++++++++++++---------------- crates/server/src/response.rs | 10 +++-- crates/wasm-adapter/src/runtime.rs | 18 ++++----- 3 files changed, 42 insertions(+), 45 deletions(-) diff --git a/crates/core/src/error/mod.rs b/crates/core/src/error/mod.rs index ef70ad363..c20523ed3 100755 --- a/crates/core/src/error/mod.rs +++ b/crates/core/src/error/mod.rs @@ -356,40 +356,30 @@ impl DynamoDbError { pub const SERIALIZATION_FAILURE_BODY: &[u8] = br#"{"__type":"com.amazonaws.dynamodb.v20120810#InternalServerError","message":"Internal error"}"#; -/// Build the DynamoDB-shaped error document for `error`. +/// Build the DynamoDB-shaped error document for `error`, as JSON bytes. /// -/// Returns the JSON body a client receives for a failed request: `__type` with -/// its namespace prefix (REQ-ERR-001), an optional message under the key -/// `message_key` picks (REQ-ERR-002), omitted when empty -/// (REQ-ERR-003 — real DynamoDB omits it for `UnknownOperationException` and -/// other messageless errors), and the `CancellationReasons` /`Item` members -/// that `TransactionCanceledException` and `ConditionalCheckFailedException` -/// carry. This is only the body; the HTTP status line and headers belong to a -/// transport and stay with the caller that has one. Error responses are part of -/// the observable contract, so every entry point builds this body the same way. +/// Returns the JSON body a client receives for a failed request, with its +/// members in the order DynamoDB writes them (us-east-1, raw bodies, +/// 2026-11-20): `__type` with its namespace prefix (REQ-ERR-001), then the +/// `CancellationReasons` of a `TransactionCanceledException` or the `Item` of +/// a `ConditionalCheckFailedException`, then the message under the key +/// `message_key` picks (REQ-ERR-002), omitted when empty (REQ-ERR-003: +/// DynamoDB omits it for `UnknownOperationException` and other messageless +/// errors). The top-level members are written one by one, so their order does +/// not depend on serde_json's `preserve_order` feature, which bson turns on in +/// any build that includes the MongoDB backend. If the body cannot be +/// serialized, the bytes are [`SERIALIZATION_FAILURE_BODY`]. This is only the +/// body; the HTTP status line and headers belong to a transport and stay with +/// the caller that has one. Error responses are part of the observable +/// contract, so every entry point builds this body the same way. #[doc(hidden)] #[must_use] -pub fn error_document(error: &DynamoDbError) -> serde_json::Value { - let mut body = serde_json::json!({ "__type": error.full_error_type() }); - let message = error.message(); - if !message.is_empty() { - body[message_key(error)] = serde_json::Value::String(message.to_owned()); - } - if let Some(reasons) = error.cancellation_reasons() { - body["CancellationReasons"] = serde_json::to_value(reasons).unwrap_or_default(); - } - if let Some(item) = error.condition_check_item() { - body["Item"] = serde_json::to_value(item).unwrap_or_default(); - } - body +pub fn error_document(error: &DynamoDbError) -> Vec { + error_body(error).unwrap_or_else(|_| SERIALIZATION_FAILURE_BODY.to_vec()) } -/// The body of `error`, with its members in the order `DynamoDB` writes them -/// (us-east-1, raw bodies, 2026-11-20): `__type` first, then the -/// `CancellationReasons` of a `TransactionCanceledException` or the `Item` of -/// a `ConditionalCheckFailedException`, then the message. -#[doc(hidden)] -pub fn error_body(error: &DynamoDbError) -> serde_json::Result> { +/// The members of [`error_document`], in its order. +fn error_body(error: &DynamoDbError) -> serde_json::Result> { let mut bytes = Vec::new(); let mut serializer = serde_json::Serializer::new(&mut bytes); let mut body = serializer.serialize_map(None)?; @@ -562,9 +552,14 @@ mod tests { assert_eq!(err.message(), "Table already exists: t"); } + /// The body `error_document` writes for `error`, parsed. + fn document(error: &DynamoDbError) -> serde_json::Value { + serde_json::from_slice(&error_document(error)).expect("an error document is JSON") + } + #[test] fn error_document_carries_type_and_message() { - let doc = error_document(&DynamoDbError::ValidationException("bad input".to_owned())); + let doc = document(&DynamoDbError::ValidationException("bad input".to_owned())); assert_eq!( doc["__type"], serde_json::json!("com.amazon.coral.validate#ValidationException") @@ -575,7 +570,7 @@ mod tests { #[test] fn error_document_omits_empty_message() { // REQ-ERR-003: real DynamoDB omits `message` when it is empty. - let doc = error_document(&DynamoDbError::UnknownOperationException(String::new())); + let doc = document(&DynamoDbError::UnknownOperationException(String::new())); assert_eq!( doc["__type"], serde_json::json!("com.amazon.coral.service#UnknownOperationException") @@ -585,7 +580,7 @@ mod tests { #[test] fn error_document_includes_cancellation_reasons() { - let doc = error_document(&DynamoDbError::TransactionCanceledException { + let doc = document(&DynamoDbError::TransactionCanceledException { message: "Transaction cancelled".to_owned(), cancellation_reasons: vec![CancellationReason { code: "ConditionalCheckFailed".to_owned(), diff --git a/crates/server/src/response.rs b/crates/server/src/response.rs index ad4f4ffa5..bf24122b7 100755 --- a/crates/server/src/response.rs +++ b/crates/server/src/response.rs @@ -5,7 +5,7 @@ use axum::http::StatusCode; use axum::response::{IntoResponse, Response}; -use extenddb_core::error::{DynamoDbError, SERIALIZATION_FAILURE_BODY, error_body}; +use extenddb_core::error::{DynamoDbError, SERIALIZATION_FAILURE_BODY, error_document}; use serde_json::Value; #[cfg(test)] @@ -34,10 +34,14 @@ pub(crate) fn success_response(body: &Value, request_id: &str) -> Response { } /// REQ-ERR-001: `__type` with prefix. REQ-ERR-002: message field, under the -/// key `error_body` picks. REQ-ERR-003: Omit the message field when empty +/// key `error_document` picks. REQ-ERR-003: Omit the message field when empty /// (real `DynamoDB` behavior, verified 2026-05-04). pub(crate) fn error_response(error: &DynamoDbError, request_id: &str) -> Response { - let body_bytes = error_body(error).unwrap_or_else(|_| SERIALIZATION_FAILURE_BODY.to_vec()); + // The body (`__type`, then `CancellationReasons` or `Item`, then the + // message) is written by the shared `error_document` helper so the wire + // body and the in-process body come from the same code; this transport adds + // the HTTP status and headers. + let body_bytes = error_document(error); let crc = crc32fast::hash(&body_bytes); let status = StatusCode::from_u16(error.status_code()).unwrap_or(StatusCode::INTERNAL_SERVER_ERROR); diff --git a/crates/wasm-adapter/src/runtime.rs b/crates/wasm-adapter/src/runtime.rs index b3b0f5566..504d221b4 100644 --- a/crates/wasm-adapter/src/runtime.rs +++ b/crates/wasm-adapter/src/runtime.rs @@ -145,13 +145,13 @@ impl Engine { /// operation that takes no parameters). #[must_use] pub async fn submit(&self, operation: &str, body_json: &str) -> String { - let value = match self.dispatch(operation, body_json).await { - Ok(body) => body, - Err(err) => error_document(&err), - }; - serde_json::to_string(&value).unwrap_or_else(|_| { - String::from_utf8_lossy(extenddb_core::error::SERIALIZATION_FAILURE_BODY).into_owned() - }) + match self.dispatch(operation, body_json).await { + Ok(body) => serde_json::to_string(&body).unwrap_or_else(|_| { + String::from_utf8_lossy(extenddb_core::error::SERIALIZATION_FAILURE_BODY) + .into_owned() + }), + Err(err) => String::from_utf8_lossy(&error_document(&err)).into_owned(), + } } /// The response to a call whose `argument` (`"operation"` or `"body"`) is @@ -162,9 +162,7 @@ impl Engine { #[must_use] pub fn non_string_argument(argument: &str) -> String { let err = DynamoDbError::ValidationException(format!("{argument} must be a string")); - serde_json::to_string(&error_document(&err)).unwrap_or_else(|_| { - String::from_utf8_lossy(extenddb_core::error::SERIALIZATION_FAILURE_BODY).into_owned() - }) + String::from_utf8_lossy(&error_document(&err)).into_owned() } /// Apply the browser-build operation policy and the engine's pre-dispatch From a4cc4fc63b6249d83f56027a0d94f8e1d782010a Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:34:24 +0000 Subject: [PATCH 3/9] test(server): compare each error body with the body DynamoDB sent the_members_follow_the_service_per_error now compares the whole body that error_response sends with the body DynamoDB sent for each row (us-east-1, 20 Nov 2026, each request twice). The comparison checks the order of the members at every depth. This commit removes the serde Visitor that read the top-level member names. The ValidationException row carries the text DynamoDB sent for a GetItem with no Key. The Item of the ConditionalCheckFailedException row holds one attribute, because DynamoDB changed the attribute order inside an Item between two sends of one request. --- crates/server/src/response_tests.rs | 70 +++++++++++++---------------- 1 file changed, 30 insertions(+), 40 deletions(-) diff --git a/crates/server/src/response_tests.rs b/crates/server/src/response_tests.rs index 75075ebf6..1e47e45b2 100644 --- a/crates/server/src/response_tests.rs +++ b/crates/server/src/response_tests.rs @@ -5,39 +5,25 @@ use extenddb_core::error::DynamoDbError; use extenddb_core::types::{AttributeValue, CancellationReason, Item}; -use serde::de::{Deserializer as _, IgnoredAny, MapAccess, Visitor}; use super::error_response; -/// The top-level member names of the body `error_response` sends for -/// `error`, in the order of the bytes. -async fn body_members(error: &DynamoDbError) -> Vec { - struct Names; - impl<'de> Visitor<'de> for Names { - type Value = Vec; - fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.write_str("an object") - } - fn visit_map>(self, mut map: A) -> Result { - let mut names = Vec::new(); - while let Some((name, IgnoredAny)) = map.next_entry::()? { - names.push(name); - } - Ok(names) - } - } +/// The body `error_response` sends for `error`. +async fn body(error: &DynamoDbError) -> String { let response = error_response(error, "request-1"); let bytes = axum::body::to_bytes(response.into_body(), usize::MAX) .await .expect("body"); - serde_json::Deserializer::from_slice(&bytes) - .deserialize_map(Names) - .expect("json object") + String::from_utf8(bytes.to_vec()).expect("UTF-8 body") } -/// Each body writes `__type` first and the other members in the order the -/// service writes them, with the message under the key the service uses for -/// that error (us-east-1, raw bodies, 2026-10-29 to 2026-11-20). +/// Each expected body is the one the service sent for that error (us-east-1, +/// raw bodies, 2026-11-20, each request twice): `__type` first, the other +/// members in the service's order, and the message under the key the service +/// uses for that error. An `Item` here holds one attribute, because the service +/// changed the order of the attributes inside an `Item` between two sends of +/// one request. The `SerializationException` with an empty text has no measured +/// body: ExtendDB omits an empty message (REQ-ERR-003). #[tokio::test] async fn the_members_follow_the_service_per_error() { let cancelled = DynamoDbError::TransactionCanceledException { @@ -52,15 +38,18 @@ async fn the_members_follow_the_service_per_error() { }; let old_item = Item::from([("pk".to_owned(), AttributeValue::S("e1222".to_owned()))]); let failed = "The conditional request failed"; - let rows: [(DynamoDbError, &[&str]); 7] = [ - (cancelled, &["__type", "CancellationReasons", "Message"]), + let rows: [(DynamoDbError, &str); 7] = [ + ( + cancelled, + r#"{"__type":"com.amazonaws.dynamodb.v20120810#TransactionCanceledException","CancellationReasons":[{"Code":"ConditionalCheckFailed","Message":"The conditional request failed"}],"Message":"Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]"}"#, + ), ( DynamoDbError::ConditionalCheckFailedException(failed.into(), Some(old_item)), - &["__type", "Item", "message"], + r#"{"__type":"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException","Item":{"pk":{"S":"e1222"}},"message":"The conditional request failed"}"#, ), ( DynamoDbError::ConditionalCheckFailedException(failed.into(), None), - &["__type", "message"], + r#"{"__type":"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException","message":"The conditional request failed"}"#, ), ( DynamoDbError::IdempotentParameterMismatchException( @@ -68,31 +57,32 @@ async fn the_members_follow_the_service_per_error() { within the idempotency window" .to_owned(), ), - &["__type", "Message"], + r#"{"__type":"com.amazonaws.dynamodb.v20120810#IdempotentParameterMismatchException","Message":"Specified idempotent token was used with different request parameters within the idempotency window"}"#, ), ( DynamoDbError::SerializationException( "STRING_VALUE cannot be converted to Integer".to_owned(), ), - &["__type", "Message"], + r#"{"__type":"com.amazon.coral.service#SerializationException","Message":"STRING_VALUE cannot be converted to Integer"}"#, ), ( DynamoDbError::SerializationException(String::new()), - &["__type"], + r#"{"__type":"com.amazon.coral.service#SerializationException"}"#, ), ( - DynamoDbError::ValidationException("One or more parameter values were invalid".into()), - &["__type", "message"], + DynamoDbError::ValidationException( + "1 validation error detected: Value null at 'key' failed to satisfy \ + constraint: Member must not be null" + .to_owned(), + ), + r#"{"__type":"com.amazon.coral.validate#ValidationException","message":"1 validation error detected: Value null at 'key' failed to satisfy constraint: Member must not be null"}"#, ), ]; let mut got = Vec::new(); - let mut want: Vec<(&str, Vec)> = Vec::new(); - for (error, members) in &rows { - got.push((error.error_type(), body_members(error).await)); - want.push(( - error.error_type(), - members.iter().map(ToString::to_string).collect(), - )); + let mut want = Vec::new(); + for (error, expected) in &rows { + got.push(body(error).await); + want.push(*expected); } assert_eq!(got, want); } From f2f28b5ca1242b6bea4638fb3cfb1d0103c075a9 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:41:57 +0000 Subject: [PATCH 4/9] fix(core): write a cancellation reason as Code, Item, Message CancellationReason now declares its fields as code, item, message. A reason serializes as Code, Item, Message, the order DynamoDB writes. The measurements (us-east-1, 20 Nov 2026, each request sent twice) used a TransactWriteItems ConditionCheck and an ExecuteTransaction UPDATE whose conditions failed with ReturnValuesOnConditionCheckFailure ALL_OLD. error_body writes the reasons directly, without the serde_json::Value round trip. Before this commit, the reasons went through a Value. A build without the MongoDB backend wrote the members of the Value in name order, which is Code, Item, Message. In a build that includes the MongoDB backend, bson enables serde_json's preserve_order, and the Value kept the field order Code, Message, Item. the_members_follow_the_service_per_error gets a row whose reason carries Item and Message. With the old field order, the row fails when error_body writes the reasons directly. Through the Value, it fails in a test build with serde_json's preserve_order enabled. --- crates/core/src/error/mod.rs | 7 +++---- crates/core/src/types/transaction.rs | 9 ++++++--- crates/server/src/response_tests.rs | 12 ++++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/core/src/error/mod.rs b/crates/core/src/error/mod.rs index c20523ed3..fe0720b8a 100755 --- a/crates/core/src/error/mod.rs +++ b/crates/core/src/error/mod.rs @@ -384,11 +384,10 @@ fn error_body(error: &DynamoDbError) -> serde_json::Result> { let mut serializer = serde_json::Serializer::new(&mut bytes); let mut body = serializer.serialize_map(None)?; body.serialize_entry("__type", &error.full_error_type())?; - // Through a `Value`, each reason writes its members in name order, as - // `DynamoDB` does: `Code`, `Item`, `Message`. + // Each reason writes `Code`, `Item`, `Message`, the field order of + // `CancellationReason` and the order `DynamoDB` writes. if let Some(reasons) = error.cancellation_reasons() { - let reasons = serde_json::to_value(reasons).unwrap_or_default(); - body.serialize_entry("CancellationReasons", &reasons)?; + body.serialize_entry("CancellationReasons", reasons)?; } if let Some(item) = error.condition_check_item() { body.serialize_entry("Item", item)?; diff --git a/crates/core/src/types/transaction.rs b/crates/core/src/types/transaction.rs index 2f311abfe..b36668fc0 100755 --- a/crates/core/src/types/transaction.rs +++ b/crates/core/src/types/transaction.rs @@ -259,17 +259,20 @@ pub struct TransactWriteItemsOutput { } /// Per-item cancellation reason in a `TransactionCanceledException`. +/// +/// The fields are declared in the order `DynamoDB` writes the members of a +/// reason (`Code`, `Item`, `Message`), and serialize in that order. #[derive(Debug, Clone, Serialize)] pub struct CancellationReason { /// Status code: `"None"`, `"ConditionalCheckFailed"`, `"ValidationError"`, etc. #[serde(rename = "Code")] pub code: String, - /// Human-readable message, omitted for items with no error. - #[serde(rename = "Message", skip_serializing_if = "Option::is_none")] - pub message: Option, /// The existing item when `ReturnValuesOnConditionCheckFailure` is `ALL_OLD`. #[serde(rename = "Item", skip_serializing_if = "Option::is_none")] pub item: Option, + /// Human-readable message, omitted for items with no error. + #[serde(rename = "Message", skip_serializing_if = "Option::is_none")] + pub message: Option, } impl CancellationReason { diff --git a/crates/server/src/response_tests.rs b/crates/server/src/response_tests.rs index 1e47e45b2..ae313e82d 100644 --- a/crates/server/src/response_tests.rs +++ b/crates/server/src/response_tests.rs @@ -26,23 +26,27 @@ async fn body(error: &DynamoDbError) -> String { /// body: ExtendDB omits an empty message (REQ-ERR-003). #[tokio::test] async fn the_members_follow_the_service_per_error() { - let cancelled = DynamoDbError::TransactionCanceledException { + let cancelled = |item: Option| DynamoDbError::TransactionCanceledException { message: "Transaction cancelled, please refer cancellation reasons for specific \ reasons [ConditionalCheckFailed]" .to_owned(), cancellation_reasons: vec![CancellationReason { code: "ConditionalCheckFailed".to_owned(), message: Some("The conditional request failed".to_owned()), - item: None, + item, }], }; let old_item = Item::from([("pk".to_owned(), AttributeValue::S("e1222".to_owned()))]); let failed = "The conditional request failed"; - let rows: [(DynamoDbError, &str); 7] = [ + let rows: [(DynamoDbError, &str); 8] = [ ( - cancelled, + cancelled(None), r#"{"__type":"com.amazonaws.dynamodb.v20120810#TransactionCanceledException","CancellationReasons":[{"Code":"ConditionalCheckFailed","Message":"The conditional request failed"}],"Message":"Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]"}"#, ), + ( + cancelled(Some(old_item.clone())), + r#"{"__type":"com.amazonaws.dynamodb.v20120810#TransactionCanceledException","CancellationReasons":[{"Code":"ConditionalCheckFailed","Item":{"pk":{"S":"e1222"}},"Message":"The conditional request failed"}],"Message":"Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]"}"#, + ), ( DynamoDbError::ConditionalCheckFailedException(failed.into(), Some(old_item)), r#"{"__type":"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException","Item":{"pk":{"S":"e1222"}},"message":"The conditional request failed"}"#, From 9bfa8239a58127c346cd4c85f8dff2f1cef1ad2d Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:43:53 +0000 Subject: [PATCH 5/9] test(wasm): check that an error answer writes __type first an_error_answer_writes_type_first sends a ListTables request with a body that is not JSON through Engine::submit. It compares the answer with the whole body the server sends for that error: __type, then Message. When the adapter wrote the serde_json::Value of error_document, the answer put Message before __type. --- crates/wasm-adapter/src/runtime.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/crates/wasm-adapter/src/runtime.rs b/crates/wasm-adapter/src/runtime.rs index 504d221b4..23aa84097 100644 --- a/crates/wasm-adapter/src/runtime.rs +++ b/crates/wasm-adapter/src/runtime.rs @@ -332,4 +332,16 @@ mod tests { ); } } + + /// An error answer is the body the server sends, with `__type` first. In + /// name order, the `Message` of a `SerializationException` would come + /// before `__type`. + #[tokio::test] + async fn an_error_answer_writes_type_first() { + let out = engine().await.submit("ListTables", "not json").await; + assert_eq!( + out, + r#"{"__type":"com.amazon.coral.service#SerializationException","Message":"Start of structure or map found where not expected: expected ident at line 1 column 2"}"# + ); + } } From 3c990b614d73512a4e2fc88269fb4a6fe3c4f1d5 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 07:55:21 +0000 Subject: [PATCH 6/9] test(core): compare the bytes of each error document error_document_writes_the_members_in_the_service_order compares the bytes that error_document writes for four errors. Two of the four carry an Item: a TransactionCanceledException in its cancellation reason, beside Message, and a ConditionalCheckFailedException at the top of the body. The order is DynamoDB's (us-east-1, 20 Nov 2026). A change of the member order in core now fails a core test. This test replaces the three tests that parsed the bytes back into a serde_json::Value, and their document helper. --- crates/core/src/error/mod.rs | 88 ++++++++++++++++++------------------ 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/crates/core/src/error/mod.rs b/crates/core/src/error/mod.rs index 69306c2e5..842eaf03a 100755 --- a/crates/core/src/error/mod.rs +++ b/crates/core/src/error/mod.rs @@ -503,6 +503,7 @@ pub fn webassembly_unsupported_message(subject: &str, reason: &str) -> String { #[cfg(test)] mod tests { use super::*; + use crate::types::AttributeValue; /// SP-ERR-002: verify every variant returns the correct HTTP status code. #[test] @@ -652,51 +653,50 @@ mod tests { ); } - /// The body `error_document` writes for `error`, parsed. - fn document(error: &DynamoDbError) -> serde_json::Value { - serde_json::from_slice(&error_document(error)).expect("an error document is JSON") - } - - #[test] - fn error_document_carries_type_and_message() { - let doc = document(&DynamoDbError::ValidationException("bad input".to_owned())); - assert_eq!( - doc["__type"], - serde_json::json!("com.amazon.coral.validate#ValidationException") - ); - assert_eq!(doc["message"], serde_json::json!("bad input")); - } - + /// The bytes of each body: `__type`, then `CancellationReasons` or `Item`, + /// then the message, which is omitted when empty (REQ-ERR-003), and a + /// cancellation reason as `Code`, `Item`, `Message`. DynamoDB wrote these + /// orders in us-east-1 on 2026-11-20 (raw bodies, each request twice). An + /// `Item` here holds one attribute, because DynamoDB changed the order of + /// the attributes inside an `Item` between two sends of one request. #[test] - fn error_document_omits_empty_message() { - // REQ-ERR-003: real DynamoDB omits `message` when it is empty. - let doc = document(&DynamoDbError::UnknownOperationException(String::new())); - assert_eq!( - doc["__type"], - serde_json::json!("com.amazon.coral.service#UnknownOperationException") - ); - assert!(doc.get("message").is_none(), "{doc}"); - } - - #[test] - fn error_document_includes_cancellation_reasons() { - let doc = document(&DynamoDbError::TransactionCanceledException { - message: "Transaction cancelled".to_owned(), - cancellation_reasons: vec![CancellationReason { - code: "ConditionalCheckFailed".to_owned(), - message: Some("The conditional request failed".to_owned()), - item: None, - }], - }); - assert_eq!(doc["Message"], serde_json::json!("Transaction cancelled")); - let reasons = doc["CancellationReasons"] - .as_array() - .expect("CancellationReasons is an array"); - assert_eq!(reasons.len(), 1); - assert_eq!( - reasons[0]["Code"], - serde_json::json!("ConditionalCheckFailed") - ); + fn error_document_writes_the_members_in_the_service_order() { + let item = Item::from([("pk".to_owned(), AttributeValue::S("e1222".to_owned()))]); + let failed = "The conditional request failed"; + let rows = [ + ( + DynamoDbError::ValidationException("bad input".to_owned()), + r#"{"__type":"com.amazon.coral.validate#ValidationException","message":"bad input"}"#, + ), + ( + DynamoDbError::UnknownOperationException(String::new()), + r#"{"__type":"com.amazon.coral.service#UnknownOperationException"}"#, + ), + ( + DynamoDbError::TransactionCanceledException { + message: + "Transaction cancelled, please refer cancellation reasons for specific \ + reasons [ConditionalCheckFailed]" + .to_owned(), + cancellation_reasons: vec![CancellationReason { + code: "ConditionalCheckFailed".to_owned(), + item: Some(item.clone()), + message: Some(failed.to_owned()), + }], + }, + r#"{"__type":"com.amazonaws.dynamodb.v20120810#TransactionCanceledException","CancellationReasons":[{"Code":"ConditionalCheckFailed","Item":{"pk":{"S":"e1222"}},"Message":"The conditional request failed"}],"Message":"Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]"}"#, + ), + ( + DynamoDbError::ConditionalCheckFailedException(failed.to_owned(), Some(item)), + r#"{"__type":"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException","Item":{"pk":{"S":"e1222"}},"message":"The conditional request failed"}"#, + ), + ]; + let got: Vec = rows + .iter() + .map(|(error, _)| String::from_utf8(error_document(error)).expect("UTF-8 body")) + .collect(); + let want: Vec<&str> = rows.iter().map(|(_, body)| *body).collect(); + assert_eq!(got, want); } #[test] From ee5eecfc82b8ad9ae2329d8f12e64cb6aaec68a3 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 07:55:21 +0000 Subject: [PATCH 7/9] test(wasm): check the order of Item and CancellationReasons an_error_answer_writes_type_first gets two cases on a table: a PutItem whose condition fails with ALL_OLD, and a TransactWriteItems whose ConditionCheck fails with ALL_OLD. The test compares each answer in full. The cases fail when Item or CancellationReasons come before __type, and when a cancellation reason writes Message before Item. --- crates/wasm-adapter/src/runtime.rs | 48 +++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 8 deletions(-) diff --git a/crates/wasm-adapter/src/runtime.rs b/crates/wasm-adapter/src/runtime.rs index 7ad1f1c24..9bbbd3c5f 100644 --- a/crates/wasm-adapter/src/runtime.rs +++ b/crates/wasm-adapter/src/runtime.rs @@ -333,15 +333,47 @@ mod tests { } } - /// An error answer is the body the server sends, with `__type` first. In - /// name order, the `Message` of a `SerializationException` would come - /// before `__type`. + /// An error answer is the body the server sends: `__type` first, then + /// `Item` or `CancellationReasons`, then the message, and a cancellation + /// reason as `Code`, `Item`, `Message`. In name order, the `Message` of a + /// `SerializationException` would come before `__type`. #[tokio::test] async fn an_error_answer_writes_type_first() { - let out = engine().await.submit("ListTables", "not json").await; - assert_eq!( - out, - r#"{"__type":"com.amazon.coral.service#SerializationException","Message":"Start of structure or map found where not expected: expected ident at line 1 column 2"}"# - ); + let engine = engine().await; + for (operation, body) in [ + ( + "CreateTable", + r#"{"TableName":"ErrorOrder","KeySchema":[{"AttributeName":"pk","KeyType":"HASH"}],"AttributeDefinitions":[{"AttributeName":"pk","AttributeType":"S"}],"BillingMode":"PAY_PER_REQUEST"}"#, + ), + ( + "PutItem", + r#"{"TableName":"ErrorOrder","Item":{"pk":{"S":"a"}}}"#, + ), + ] { + ok_value(&engine.submit(operation, body).await); + } + let cases = [ + ( + "ListTables", + "not json", + r#"{"__type":"com.amazon.coral.service#SerializationException","Message":"Start of structure or map found where not expected: expected ident at line 1 column 2"}"#, + ), + ( + "PutItem", + r#"{"TableName":"ErrorOrder","Item":{"pk":{"S":"a"}},"ConditionExpression":"attribute_not_exists(pk)","ReturnValuesOnConditionCheckFailure":"ALL_OLD"}"#, + r#"{"__type":"com.amazonaws.dynamodb.v20120810#ConditionalCheckFailedException","Item":{"pk":{"S":"a"}},"message":"The conditional request failed"}"#, + ), + ( + "TransactWriteItems", + r#"{"TransactItems":[{"ConditionCheck":{"TableName":"ErrorOrder","Key":{"pk":{"S":"a"}},"ConditionExpression":"attribute_not_exists(pk)","ReturnValuesOnConditionCheckFailure":"ALL_OLD"}}]}"#, + r#"{"__type":"com.amazonaws.dynamodb.v20120810#TransactionCanceledException","CancellationReasons":[{"Code":"ConditionalCheckFailed","Item":{"pk":{"S":"a"}},"Message":"The conditional request failed"}],"Message":"Transaction cancelled, please refer cancellation reasons for specific reasons [ConditionalCheckFailed]"}"#, + ), + ]; + let mut got = Vec::new(); + for (operation, body, _) in cases { + got.push(engine.submit(operation, body).await); + } + let want: Vec<&str> = cases.iter().map(|(_, _, answer)| *answer).collect(); + assert_eq!(got, want); } } From 2c9ac40255ef66bc3e96021878dbc67becddeb03 Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 07:55:21 +0000 Subject: [PATCH 8/9] test(server): check the Item members of two error bodies on the wire tests/test_error_message_key.py gets an ALL_OLD row for a PutItem whose condition fails and for a TransactWriteItems whose ConditionCheck fails. The TransactWriteItems rows also check the members of the cancellation reason. The helper returns the body, and each test reads the members in the order of the bytes. DynamoDB wrote these orders on 20 Nov 2026. The two requests need a table, so they were not measured again for this change. --- tests/test_error_message_key.py | 76 ++++++++++++++++++++++++--------- 1 file changed, 55 insertions(+), 21 deletions(-) diff --git a/tests/test_error_message_key.py b/tests/test_error_message_key.py index 9a47c7dd0..81e1412fc 100644 --- a/tests/test_error_message_key.py +++ b/tests/test_error_message_key.py @@ -15,6 +15,13 @@ either key, so these tests read the raw body from botocore's ``before-parse`` event before it normalizes it. +With ``ReturnValuesOnConditionCheckFailure`` set to ``ALL_OLD``, DynamoDB +wrote ``__type``, ``Item``, ``message`` for a PutItem whose condition failed, +and ``__type``, ``CancellationReasons``, ``Message`` for a TransactWriteItems +whose ConditionCheck failed, with ``Code``, ``Item``, ``Message`` in the +reason (us-east-1, 2026-11-20, each request twice). These two requests need +a table, so they were not measured again for these tests. + Dual-target against Amazon DynamoDB and extenddb. """ @@ -41,10 +48,10 @@ def hash_table(dynamodb_client): yield name -def _error_code_and_keys(client, operation: str, call) -> tuple[str, list[str], int]: - """Run ``call``, which must fail, and return the error code, the - top-level keys of the raw response body in the order of the bytes, and - the HTTP status.""" +def _error_code_and_body(client, operation: str, call) -> tuple[str, dict, int]: + """Run ``call``, which must fail, and return the error code, the raw + response body with its members in the order of the bytes, and the HTTP + status.""" raw: list[bytes] = [] def capture(response_dict, **_kwargs): @@ -60,13 +67,25 @@ def capture(response_dict, **_kwargs): response = exc_info.value.response return ( response["Error"]["Code"], - list(json.loads(raw[-1])), + json.loads(raw[-1]), response["ResponseMetadata"]["HTTPStatusCode"], ) -def test_transaction_canceled_carries_message_under_capital_m(dynamodb_client, hash_table): - code, keys, _ = _error_code_and_keys( +@pytest.mark.parametrize( + "return_values, reason_keys", + [ + ({}, ["Code", "Message"]), + ({"ReturnValuesOnConditionCheckFailure": "ALL_OLD"}, ["Code", "Item", "Message"]), + ], + ids=["NONE", "ALL_OLD"], +) +def test_transaction_canceled_carries_message_under_capital_m( + dynamodb_client, hash_table, return_values, reason_keys +): + pk = f"held-{uuid.uuid4().hex}" + dynamodb_client.put_item(TableName=hash_table, Item={"pk": {"S": pk}}) + code, body, _ = _error_code_and_body( dynamodb_client, "TransactWriteItems", lambda: dynamodb_client.transact_write_items( @@ -74,15 +93,17 @@ def test_transaction_canceled_carries_message_under_capital_m(dynamodb_client, h { "ConditionCheck": { "TableName": hash_table, - "Key": {"pk": {"S": f"missing-{uuid.uuid4().hex}"}}, - "ConditionExpression": "attribute_exists(pk)", + "Key": {"pk": {"S": pk}}, + "ConditionExpression": "attribute_not_exists(pk)", + **return_values, } } ] ), ) assert code == "TransactionCanceledException" - assert keys == ["__type", "CancellationReasons", "Message"] + assert list(body) == ["__type", "CancellationReasons", "Message"] + assert [list(reason) for reason in body["CancellationReasons"]] == [reason_keys] def test_idempotent_parameter_mismatch_carries_message_under_capital_m( @@ -100,11 +121,11 @@ def put(value: str): ) put("first") - code, keys, _ = _error_code_and_keys( + code, body, _ = _error_code_and_body( dynamodb_client, "TransactWriteItems", lambda: put("second") ) assert code == "IdempotentParameterMismatchException" - assert keys == ["__type", "Message"] + assert list(body) == ["__type", "Message"] # Raw bodies measured in us-east-1 on 2026-11-20, each request sent twice, @@ -138,32 +159,45 @@ def test_serialization_error_carries_message_under_capital_m( ): client = dynamodb_client_no_validation call = getattr(client, xform_name(operation)) - code, keys, status = _error_code_and_keys(client, operation, lambda: call(**params)) + code, body, status = _error_code_and_body(client, operation, lambda: call(**params)) # The texts are not asserted: ExtendDB's texts differ from DynamoDB's (#1012, #884). assert status == 400 assert code == "SerializationException" - assert keys == ["__type", "Message"] + assert list(body) == ["__type", "Message"] -def test_conditional_check_failed_carries_message_under_lower_case(dynamodb_client, hash_table): - code, keys, _ = _error_code_and_keys( +@pytest.mark.parametrize( + "return_values, keys", + [ + ({}, ["__type", "message"]), + ({"ReturnValuesOnConditionCheckFailure": "ALL_OLD"}, ["__type", "Item", "message"]), + ], + ids=["NONE", "ALL_OLD"], +) +def test_conditional_check_failed_carries_message_under_lower_case( + dynamodb_client, hash_table, return_values, keys +): + pk = f"held-{uuid.uuid4().hex}" + dynamodb_client.put_item(TableName=hash_table, Item={"pk": {"S": pk}}) + code, body, _ = _error_code_and_body( dynamodb_client, "PutItem", lambda: dynamodb_client.put_item( TableName=hash_table, - Item={"pk": {"S": f"missing-{uuid.uuid4().hex}"}}, - ConditionExpression="attribute_exists(pk)", + Item={"pk": {"S": pk}}, + ConditionExpression="attribute_not_exists(pk)", + **return_values, ), ) assert code == "ConditionalCheckFailedException" - assert keys == ["__type", "message"] + assert list(body) == keys def test_validation_error_carries_message_under_lower_case(dynamodb_client, hash_table): - code, keys, _ = _error_code_and_keys( + code, body, _ = _error_code_and_body( dynamodb_client, "GetItem", lambda: dynamodb_client.get_item(TableName=hash_table, Key={"pk": {"N": "1"}}), ) assert code == "ValidationException" - assert keys == ["__type", "message"] + assert list(body) == ["__type", "message"] From 77cb9b6755de2f58ab43fd5571b6ab5c3b27ddba Mon Sep 17 00:00:00 2001 From: Lee Hannigan <29015211+LeeroyHannigan@users.noreply.github.com> Date: Thu, 3 Dec 2026 07:56:20 +0000 Subject: [PATCH 9/9] docs(upgrade): add the v1.2.0 entry for the error member order Behavior Changes by Release gets a v1.2.0 entry for this change, after the entry for the SerializationException key. An error body writes __type first, then CancellationReasons or Item, then the message, and a cancellation reason writes Code, Item, Message, in every build. A client that compares the raw bytes of an error body sees the new order. --- docs/manuals/07-upgrade-manual.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/manuals/07-upgrade-manual.md b/docs/manuals/07-upgrade-manual.md index 4399c1c95..5c625912d 100755 --- a/docs/manuals/07-upgrade-manual.md +++ b/docs/manuals/07-upgrade-manual.md @@ -416,6 +416,12 @@ deployment, even when no catalog migration is required. **Who is affected.** A client that reads `message` from the raw body of a `SerializationException` finds the text under `Message` instead. No catalog migration or configuration change is required. +### v1.2.0: an error body writes `__type` first + +**What changed** (#1249, fixes #1222). An error body writes `__type` first, then `CancellationReasons` or `Item`, then the message, as DynamoDB writes them (measured 2026-11-20). A cancellation reason writes `Code`, `Item`, `Message`. In 1.1.0, a build without the MongoDB backend, such as the WebAssembly build, wrote the members in name order, so `CancellationReasons`, `Item` and `Message` came before `__type`. A build with the MongoDB backend wrote `__type`, then the message, then `CancellationReasons` or `Item`, and wrote a reason as `Code`, `Message`, `Item`. The new order applies in every build. + +**Who is affected.** A client that compares the raw bytes of an error body, or reads its members in order. A client that looks up the members by name sees no change. No catalog migration or configuration change is required. + ### v1.1.0: latency `segments` are summed into time buckets **What changed** (#398). The latency `segments` that `/metrics` and the console's `/console/metrics-data` return come from time buckets per account and operation. 1.0.0 kept one record per request for 24 hours. Each operation's count and means are still exact over the requests that the window covers. Four things change: