Skip to content

Commit

Permalink
fix default onError callback values for watch() and onChange() (#134)
Browse files Browse the repository at this point in the history
Co-authored-by: Christiaan Landman <[email protected]>
  • Loading branch information
Chriztiaan and Christiaan Landman authored Apr 19, 2024
1 parent 36fed1a commit f9b9a96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/rare-pumpkins-study.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@journeyapps/powersync-sdk-common": patch
---

Fixed default onError callback for watch() and onChange() that used an unbounded member.
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
* Note that the `onChange` callback member of the handler is required.
*/
watchWithCallback(sql: string, parameters?: any[], handler?: WatchHandler, options?: SQLWatchOptions): void {
const { onResult, onError = this.options.logger?.error } = handler ?? {};
const { onResult, onError = (e: Error) => this.options.logger?.error(e) } = handler ?? {};
if (!onResult) {
throw new Error('onResult is required');
}
Expand Down Expand Up @@ -829,7 +829,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
* Returns dispose function to stop watching.
*/
onChangeWithCallback(handler?: WatchOnChangeHandler, options?: SQLWatchOptions): () => void {
const { onChange, onError = this.options.logger?.error } = handler ?? {};
const { onChange, onError = (e: Error) => this.options.logger?.error(e) } = handler ?? {};
if (!onChange) {
throw new Error('onChange is required');
}
Expand Down

0 comments on commit f9b9a96

Please sign in to comment.