Skip to content

Commit

Permalink
feat: throw an error if an infused transaction is a no-op
Browse files Browse the repository at this point in the history
  • Loading branch information
icidasset committed Dec 15, 2023
1 parent e1fda8d commit a21de2a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 2 additions & 0 deletions packages/nest/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://fission-codes.github.io/stack>
Expand Down
10 changes: 6 additions & 4 deletions packages/nest/src/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,11 +699,13 @@ export class FileSystem {
): Promise<MutationResult<Partition>> {
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) {
Expand Down

0 comments on commit a21de2a

Please sign in to comment.