Table of Contents

Class ConditionalCheckFailedException

Namespace
DynaSharp
Assembly
DynaSharp.dll

The condition expression of a write did not hold, so nothing was written. Not retried by the client, because the same request meets the same condition. Code that reads again and decides again can run in RetryOnConflictAsync<TResult>(Func<CancellationToken, ValueTask<TResult>>, CancellationToken), which repeats it for you. Key says which item it was about.

public sealed class ConditionalCheckFailedException : DynamoDbException, ISerializable
Inheritance
ConditionalCheckFailedException
Implements
Inherited Members

Remarks

DynamoDB says no more than "The conditional request failed". After a Put, Update or Delete of a table, Message gains a line that says which condition the write sent: the version check, named by its attribute, the check that no item or that an item has the key, or the caller's own condition, all of them when there were several, because DynamoDB does not say which part failed. A version that marks a new item says so, with the two ways to write over the stored one. The line names attributes and the table and never a value, so the exception is as safe to log as any other.

Constructors

ConditionalCheckFailedException(string, Item?, string?, HttpStatusCode)

Initializes a new instance of the ConditionalCheckFailedException class.

public ConditionalCheckFailedException(string message, Item? item = null, string? requestId = null, HttpStatusCode statusCode = HttpStatusCode.BadRequest)

Parameters

message string

The error message returned by DynamoDB.

item Item

The existing item, if the request asked for it.

requestId string

The AWS request id, if known.

statusCode HttpStatusCode

The HTTP status code of the response.

Properties

Item

Gets the item the condition was evaluated against, when the request set AllOld and an item existed; otherwise null. On a typed table, To<T>() reads it as the entity.

public Item? Item { get; }

Property Value

Item

Key

Gets the key of the item the condition was checked on, as the request named it (pk, sk), or null where the request has no key names. Never in Message, ToString(), logs or telemetry.

public Item? Key { get; }

Property Value

Item

Remarks

A caller that holds the key gains nothing from this, because it is the key that caller passed. It is for code that does not hold it: a wrapper around a delegate, a handler at the edge of a service, the last run of a retry. The client puts it in no log, so what such code logs is its own decision.

catch (ConditionalCheckFailedException exception) when (exception.Key is { } key)
{
    var customerId = Customer.Keys.Pk.Parse(key.GetString("pk")!).Id;
    return Results.Conflict(customerId);
}

DynamoDB does not send the key, so the client takes it from the request: Put, Update and Delete of a table, typed or of Item, and UpdateItemAsync(DynamoDbClient, UpdateItemRequest, CancellationToken) and DeleteItemAsync(DynamoDbClient, DeleteItemRequest, CancellationToken). A Put reads the key attributes of the table from its item. It is null on PutItemAsync(DynamoDbClient, PutItemRequest, CancellationToken), whose request does not say which attributes are the key, on SendRawAsync(string, ReadOnlyMemory<byte>, CancellationToken), whose JSON is not read, in a transaction, where ItemFor(TransactMarker) is the way to an item, and on an exception made elsewhere. It does not depend on AllOld, which fills Item as well.

The values are what is stored, such as USER#alice. For a key of a template the generated builders give the inputs back: Customer.Keys.Pk.Parse(exception.Key!.GetString("pk")!). A plain key is its input.

It is taken from the request only when the condition fails. After the last run of RetryOnConflictAsync<TResult>(Func<CancellationToken, ValueTask<TResult>>, CancellationToken) it is the key of that run.

Message

Gets the message of the service, followed for a command by a line that says which condition the write sent.

public override string Message { get; }

Property Value

string