Moved from GitHub dgraph-js/48
Posted by AlexandreDaSilva:
Hello!
I think the client has a strange behavior when we call discard() after some mutations: it throws the following error : Transaction has been aborted. Please retry. I don’t think it is useful, because if I call this method, it’s precisely because I want to abort the transaction (and didn’t call commit())…
In this case, I noticed that the error object has an additionnal property code with the value 10, and the following is false: e == dgraph.ERR_ABORTED.
Although the error message is the same, the error thrown when a conflict occurs during a transaction doesn’t have this property code, and we can assert that: e == dgraph.ERR_ABORTED.
In my project, I currently monkey-patch the library the following way…
// Change behavior of discard.
// When calling discard() after mutations, it throws the error "10 ABORTED: Transaction has been aborted. Please retry.";
const _discard = Txn.prototype.discard;
Txn.prototype.discard = async function() {
try {
await _discard.apply(this, arguments);
} catch (e) {
if (e.code != 10) throw e;
}
};
It is annoying because, usually, the call to discard() occurs in a finally block, so the error is not handled properly.
What do you think about this issue? Is this a desired behavior?
Thanks in advance for your answers. 