Skip to content
This repository was archived by the owner on Mar 3, 2025. It is now read-only.

Commit 44f6f8d

Browse files
vpbs2ujaval403
authored andcommitted
add: error handler
1 parent 985ff9e commit 44f6f8d

File tree

2 files changed

+51
-11
lines changed

2 files changed

+51
-11
lines changed

packages/duckdb-wasm/src/bindings/bindings_browser_base.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,47 @@ export abstract class DuckDBBrowserBindings extends DuckDBBindingsBase {
8989
};
9090
// Instantiate streaming
9191
const response = fetchWithProgress();
92-
WebAssembly.instantiateStreaming(response, imports).then(output => {
93-
success(output.instance, output.module);
94-
});
92+
93+
const initiateStreaming = async () => {
94+
await WebAssembly.instantiateStreaming(response, imports).then(output => {
95+
success(output.instance, output.module);
96+
}).catch(error => {
97+
this.logger.log({
98+
timestamp: new Date(),
99+
level: LogLevel.ERROR,
100+
origin: LogOrigin.BINDINGS,
101+
topic: LogTopic.INSTANTIATE,
102+
event: LogEvent.ERROR,
103+
value: 'Failed to instantiate WASM: ' + error,
104+
});
105+
throw new Error(error);
106+
});
107+
};
108+
109+
initiateStreaming();
110+
95111
} else {
96112
console.warn('instantiating without progress handler since transform streams are unavailable');
97113
const request = new Request(this.mainModuleURL);
98-
WebAssembly.instantiateStreaming(fetch(request), imports).then(output => {
99-
success(output.instance, output.module);
100-
});
114+
115+
const initiateStreaming = async () => {
116+
await WebAssembly.instantiateStreaming(fetch(request), imports).then(output => {
117+
success(output.instance, output.module);
118+
}).catch(error => {
119+
this.logger.log({
120+
timestamp: new Date(),
121+
level: LogLevel.ERROR,
122+
origin: LogOrigin.BINDINGS,
123+
topic: LogTopic.INSTANTIATE,
124+
event: LogEvent.ERROR,
125+
value: 'Failed to instantiate WASM: ' + error,
126+
});
127+
throw new Error(error);
128+
});
129+
};
130+
131+
initiateStreaming();
132+
101133
}
102134
} else if (typeof XMLHttpRequest == 'function') {
103135
// Otherwise we fall back to XHRs

packages/duckdb-wasm/src/bindings/bindings_browser_eh.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ export class DuckDB extends DuckDBBrowserBindings {
1818

1919
/** Instantiate the bindings */
2020
protected instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule> {
21-
return DuckDBWasm({
22-
...moduleOverrides,
23-
instantiateWasm: this.instantiateWasm.bind(this),
24-
locateFile: this.locateFile.bind(this),
25-
});
21+
try{
22+
const wasm = this.instantiateWasm.bind(this);
23+
const locateFile = this.locateFile.bind(this);
24+
25+
return DuckDBWasm({
26+
...moduleOverrides,
27+
instantiateWasm: wasm,
28+
locateFile: locateFile,
29+
});
30+
} catch (e) {
31+
console.error(e);
32+
throw e;
33+
}
2634
}
2735
}
2836

0 commit comments

Comments
 (0)