orbitinghail / sqlsync

SQLSync is a collaborative offline-first wrapper around SQLite. It is designed to synchronize web application state between users, devices, and the edge.
https://sqlsync.dev
Apache License 2.0
2.19k stars 28 forks source link

Make it possible for reducers to handle errors #29

Closed carlsverre closed 7 months ago

carlsverre commented 7 months ago

Now, reducers can handle errors. Before errors were silently handled in the host which led to the reactor failing in a half-open state (thus all future calls into the reactor would fail). Now errors are passed back from the host into the reducer where it can either handle it or fail in a closed state (as in the reactor task is cleaned up).

Fixes #27

To upgrade to this version of SQLSync you will need to recompile your Reducers after making the following changes:

Before:

execute!(
    "INSERT INTO kv (key, value) VALUES (?, ?)
    ON CONFLICT (key) DO UPDATE SET value = VALUES(value)",
    key,
    value
)
.await;

After:

execute!(
    "INSERT INTO kv (key, value) VALUES (?, ?)
    ON CONFLICT (key) DO UPDATE SET value = VALUES(value)",
    key,
    value
)
.await?;

(It's very subtle, the only change is adding a ? after the await to forward the error to the caller.)