firebase / firebase/firebase-js-sdk

runTransaction errors are not catchable

Open
#7,919 3 comments 0 reactions 0 assignees View on GitHub
api: database needs-attention question reproducible testing-sdk
Dominant language
TypeScript
Stars
5.1k
Forks
1k
Avg merge
2d 21h
Merged PRs (30d)
37

Description

### Operating System

macOS

### Browser Version

Safari 16.5.2

### Firebase SDK Version

10.7.1

### Firebase SDK Product:

Database

### Describe your project's tooling

index.html with source tag. Just javascript.

### Describe the problem

runTransaction errors can not be caught.

### Steps and code to reproduce issue

Start with the database empty.

```
var db = getDatabase();
connectDatabaseEmulator(db, '127.0.0.1', 9000);
await update(ref(db, "users/testUser/starCount"), { starCount: increment(1) });
try {
await runTransaction(ref(db, "users/testUser"), post => {
console.log(post);
if (post) {
var starCount = post["starCount"];
starCount++;
post["starCount"] = starCount;
return post;
} else {
return null;
}
});
} catch (e) {//it never reaches catch
console.error("transaction error");
console.error(e);
}
```

The following error shows up on the console

`Error: transaction failed: Data returned contains NaN in property 'users.testUser.starCount'`

However, the error can never be caught. I also tried using a try catch block inside the transaction itself, and it still didn't work.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.