Commit 42068e4
fix(realtime_client): stop throwing internally when converting null cell values (#1612)
## What kind of change does this PR introduce?
Bug fix (internal exception noise; no observable behavior change).
## What is the current behavior?
`convertCell`'s doc comment says *"If the value of the cell is `null`,
returns null"* — but the code never checks for null. A null value in an
`int2/int4/int8/oid` (or `float4/float8/numeric`) column falls through
to `toInt`/`toDouble`, which do:
```dart
try {
return int.parse(value.toString()); // null → "null" → FormatException
} catch (_) {
return null;
}
```
So every `postgres_changes` payload containing a null numeric column
throws (and immediately catches) `FormatException: Invalid radix-10
number (at character 1) null` inside the library.
The converted result is correct, but the exception-as-control-flow fires
on **every CDC frame** for any subscribed table with nullable numeric
columns. In practice this means anyone debugging a realtime Flutter app
with "break on all exceptions" enabled gets stopped in
`integers_patch.dart` constantly, with no way to silence it from app
code.
For reference, realtime-js doesn't have this problem: its `toNumber`
only parses `typeof value === 'string'` and passes null through
untouched.
## What is the new behavior?
- `convertCell` short-circuits `null` → `null`, matching its own
documented behavior and realtime-js
- `toInt`/`toDouble` use `tryParse` instead of `parse` inside try/catch,
so unparseable strings also no longer throw internally
Output is unchanged for every input — existing tests already pin
`convertCell('int8', null) => null` and `convertCell('float8', null) =>
null`, and they still pass. Added direct unit tests for
`toInt`/`toDouble` covering null, empty, and non-numeric inputs.
## Additional context
Repro: subscribe to `postgres_changes` on any table with a nullable
`integer` column, update a row while the column is null, run with a
debugger set to break on all exceptions.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>1 parent 2c961c0 commit 42068e4
2 files changed
Lines changed: 25 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
129 | 129 | | |
130 | 130 | | |
131 | 131 | | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
132 | 136 | | |
133 | 137 | | |
134 | 138 | | |
| |||
197 | 201 | | |
198 | 202 | | |
199 | 203 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | | - | |
| 204 | + | |
204 | 205 | | |
205 | 206 | | |
| 207 | + | |
206 | 208 | | |
207 | 209 | | |
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
211 | 213 | | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
| 214 | + | |
216 | 215 | | |
217 | 216 | | |
| 217 | + | |
218 | 218 | | |
219 | 219 | | |
220 | 220 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
23 | 40 | | |
24 | 41 | | |
25 | 42 | | |
| |||
0 commit comments