Abort

Not available in this language yet.
Not available in this language yet.
Abort( message )
Abort( message )
Not available in this language yet.
Abort( message )

Description

The Abort function terminates the current transaction and augments the returned error with the associated message. Any modifications to data or schema in the aborted transaction are ignored, even if this modification took place before the abort function was executed.

Parameters

Argument

Type

Definition and Requirements

message

String

An abort message.

Returns

An error is returned with the associated abort message.

Examples

The query below is a single transaction with three statements. The first statement creates a collection, the second statement adds an document to the collection, and the third statement aborts the transaction. Due to the transaction being terminated by the Abort call, neither the creation of the collection nor the addition of the document is present in the database.

Not available in this language yet.
Not available in this language yet.
try {
    System.out.println(client.query(
        Arr(
            CreateCollection(Obj("name", Value("cars"))),
            Now(),
            Abort("Reset Transaction")
        )
    ).get());
} catch (Exception e) {
    System.out.println("ERROR " + e.getMessage());
}
ERROR com.faunadb.client.errors.BadRequestException: transaction aborted: Reset Transaction
client.query([
  q.CreateCollection({ name: 'cars' }),
  q.Now(),
  q.Abort('Reset Transaction'),
])
.then((ret) => console.log(ret))
.catch((err) => console.error(
  'Error: [%s] %s: %s',
  err.name,
  err.message,
  err.errors()[0].description,
))
Error: [BadRequest] transaction aborted: Reset Transaction
Not available in this language yet.
val result = client.query(
  Arr(
    CreateCollection(Obj("name" -> "cars")),
    Now(),
    Abort("Reset Transaction")
  )
).recover {
  case error: Any => "Error: " + error.getMessage()
}.andThen {
  case _ => client.close()
}
println(Await.result(result, 5.seconds))
Error: transaction aborted: Reset Transaction

Was this article helpful?

We're sorry to hear that.
Tell us how we can improve!
Visit Fauna's Discourse forums or email docs@fauna.com

Thank you for your feedback!