dyna-record
    Preparing search index...

    Class WriteConditionFailedError

    Error thrown, inside a TransactionWriteFailedError, when a consumer's write condition does not hold and the write is not made.

    DynamoDB reports only that a row's combined check failed, so when more than one consumer guard landed on that row, every one of them is named.

    A row that does not exist, a failed referential-integrity check, a relationship that changed concurrently, or a HasMany or HasAndBelongsToMany id that is not related is reported as a plain ConditionalCheckFailedError instead, never as this error. A guard whose target cannot be found in what is stored, such as a BelongsTo whose foreign key is null, is reported as this error before anything is sent.

    Its message names the write and the guards, for example ConditionalCheckFailed: Write condition failed on Order with ID 'order-1': its own row.

    try {
    await Order.update(
    "order-1",
    { status: "cancelled" },
    { condition: { status: "pending", customer: { status: "active" } } }
    );
    } catch (error) {
    if (error instanceof TransactionWriteFailedError) {
    for (const cause of error.errors) {
    if (cause instanceof WriteConditionFailedError) {
    // cause.entity === "Order", cause.id === "order-1", and cause.guards
    // names the failed row's guards: [{ kind: "self" }] or
    // [{ kind: "relationship", name: "customer" }]
    console.log(cause.entity, cause.id, cause.guards);
    }
    }
    }
    throw error;
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    Constructors

    Properties

    code: "WriteConditionFailedError"

    Widened to every subclass's code, so a subclass can narrow it. An instance of this class itself always carries "ConditionalCheckFailedError", and a WriteConditionFailedError carries "WriteConditionFailedError". Comparing code and testing instanceof work for either class; only code that assigns code to a variable typed as the single literal "ConditionalCheckFailedError" needs to widen that variable.

    entity: string

    The name of the entity being written, or of the join table for a join table's create or delete

    guards: readonly WriteConditionGuard[]

    Every consumer guard on the row whose check failed

    id: string

    The id of the entity being written. For a join table, its keys, such as customerId=customer-1, storeId=store-1