commit 7eb77387e8d1c8f929946f0c1564484c50b2637e
parent f85428e4244c0181e8c58f9292a41bb460c9c7c8
Author: Florian Dold <florian@dold.me>
Date: Tue, 7 Jan 2025 20:40:19 +0100
idb-bridge: improve error reporting for sqlite3 helper
Diffstat:
1 file changed, 10 insertions(+), 0 deletions(-)
diff --git a/packages/idb-bridge/src/node-helper-sqlite3-impl.ts b/packages/idb-bridge/src/node-helper-sqlite3-impl.ts
@@ -74,12 +74,21 @@ class Helper {
private enableTracing: boolean;
private isListening: boolean = false;
public proc: ChildProcessByStdio<stream.Writable, stream.Readable, null>;
+ private promStarted: Promise<void>;
constructor(opts?: { enableTracing: boolean }) {
this.enableTracing = opts?.enableTracing ?? false;
this.proc = child_process.spawn("taler-helper-sqlite3", {
stdio: ["pipe", "pipe", "inherit"],
});
+ const startedPromcap = openPromise<void>();
+ this.promStarted = startedPromcap.promise;
+ this.proc.on("error", (err: Error) => {
+ startedPromcap.reject(err);
+ });
+ this.proc.on("spawn", () => {
+ startedPromcap.resolve();
+ });
// Make sure that the process is not blocking the parent process
// from exiting.
// When we are actively waiting for a response, we ref it again.
@@ -168,6 +177,7 @@ class Helper {
}
async communicate(cmd: number, payload: Uint8Array): Promise<Uint8Array> {
+ await this.promStarted;
if (!this.isListening) {
this.startListening();
}