Skip to content

Commit

Permalink
fixed async queue swallowing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
carlsverre committed Mar 10, 2024
1 parent e02cef3 commit 888a9ce
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ If you are interested in using or contributing to SQLSync, please [join the Disc

Please refer to [the guide](./GUIDE.md) to learn how to add SQLSync to your application.

## Tips & Tricks

### How to debug SQLSync in the browser
By default SQLSync runs in a shared web worker. This allows the database to automatically be shared between different tabs, however results in making SQLSync a bit harder to debug.

The easiest way is to use Google Chrome, and go to the special URL: [chrome://inspect/#workers](chrome://inspect/#workers). On that page you'll find a list of all the running shared workers in other tabs. Assuming another tab is running SQLSync, you'll see the shared worker listed. Click `inspect` to open up dev-tools for the worker.

## Community & Contributing

If you are interested in contributing to SQLSync, please [join the Discord community][discord] and let us know what you want to build. All contributions will be held to a high standard, and are more likely to be accepted if they are tied to an existing task and agreed upon specification.
Expand Down
3 changes: 2 additions & 1 deletion lib/sqlsync-worker/sqlsync-wasm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ pub async fn fetch_reducer(reducer_url: &str) -> Result<(WasmReducer, Vec<u8>),
Uint8Array::new(&digest).to_vec()
};

let reducer = WasmReducer::new(reducer_wasm_bytes.as_slice())?;
let reducer = WasmReducer::new(reducer_wasm_bytes.as_slice())
.map_err(|err| anyhow!("failed to instantiate reducer from wasm: {}", err))?;

Ok((reducer, digest))
}
Expand Down
11 changes: 6 additions & 5 deletions lib/sqlsync-worker/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ const MessageQueue = (() => {
let queue = Promise.resolve();
return {
push: (m: Message) => {
queue = queue.then(
() => handleMessage(m),
(e) => {
queue = queue.then(async () => {
try {
await handleMessage(m);
} catch (e) {
const err = e instanceof Error ? e.message : `error: ${JSON.stringify(e)}`;
reply(m.portId, m.req.handlerId, { tag: "Err", err });
},
);
}
});
},
};
})();
Expand Down

0 comments on commit 888a9ce

Please sign in to comment.