From a21de2a44af92676e78f4c600bea4def29f2be82 Mon Sep 17 00:00:00 2001 From: Steven Vandevelde Date: Fri, 15 Dec 2023 15:53:13 +0100 Subject: [PATCH] feat: throw an error if an infused transaction is a no-op --- packages/nest/readme.md | 2 ++ packages/nest/src/class.ts | 10 ++++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/nest/readme.md b/packages/nest/readme.md index 16c3305..9a458ae 100644 --- a/packages/nest/readme.md +++ b/packages/nest/readme.md @@ -110,6 +110,8 @@ const fs = FileSystem.create({ }) ``` +When you make a modification through the `transaction` method and the commit ends up not being approved, this will result in a `"no-op"` string. In the case of using a regular mutation method such as `write` it will produce an error. + ## Docs Check diff --git a/packages/nest/src/class.ts b/packages/nest/src/class.ts index ce2cfef..c8f370b 100644 --- a/packages/nest/src/class.ts +++ b/packages/nest/src/class.ts @@ -699,11 +699,13 @@ export class FileSystem { ): Promise> { const transactionResult = await this.transaction(handler, mutationOptions) - const dataRoot = - transactionResult === 'no-op' - ? await this.calculateDataRoot() - : transactionResult.dataRoot + if (transactionResult === 'no-op') { + throw new Error( + 'The transaction was a no-op, most likely as a result of the commit not being approved by the `onCommit` verifier.' + ) + } + const dataRoot = transactionResult.dataRoot const partition = determinePartition(path) switch (partition.name) {