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

Commit 41e390b

Browse files
authored
Merge pull request #6 from devrev/fix/dashboard-wasm-bala
fix: duckdb instatiation error fix
2 parents 985ff9e + 4068771 commit 41e390b

File tree

2 files changed

+68
-14
lines changed

2 files changed

+68
-14
lines changed

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

+45-7
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export abstract class DuckDBBrowserBindings extends DuckDBBindingsBase {
3434
}
3535

3636
/** Instantiate the wasm module */
37-
protected instantiateWasm(
37+
protected async instantiateWasm(
3838
// eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types
3939
imports: any,
4040
success: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void,
@@ -89,15 +89,53 @@ 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+
try{
95+
const output = await WebAssembly.instantiateStreaming(response, imports);
96+
success(output.instance, output.module);
97+
98+
} catch (error: any) {
99+
this.logger.log({
100+
timestamp: new Date(),
101+
level: LogLevel.ERROR,
102+
origin: LogOrigin.BINDINGS,
103+
topic: LogTopic.INSTANTIATE,
104+
event: LogEvent.ERROR,
105+
value: 'Failed to instantiate WASM: ' + error,
106+
});
107+
108+
throw error;
109+
}
110+
};
111+
112+
await initiateStreaming();
113+
95114
} else {
96115
console.warn('instantiating without progress handler since transform streams are unavailable');
97116
const request = new Request(this.mainModuleURL);
98-
WebAssembly.instantiateStreaming(fetch(request), imports).then(output => {
99-
success(output.instance, output.module);
100-
});
117+
118+
const initiateStreaming = async () => {
119+
try {
120+
const output = await WebAssembly.instantiateStreaming(fetch(request), imports);
121+
success(output.instance, output.module);
122+
123+
} catch (error: any){
124+
this.logger.log({
125+
timestamp: new Date(),
126+
level: LogLevel.ERROR,
127+
origin: LogOrigin.BINDINGS,
128+
topic: LogTopic.INSTANTIATE,
129+
event: LogEvent.ERROR,
130+
value: 'Failed to instantiate WASM: ' + error,
131+
});
132+
133+
throw error;
134+
}
135+
};
136+
137+
await initiateStreaming();
138+
101139
}
102140
} else if (typeof XMLHttpRequest == 'function') {
103141
// Otherwise we fall back to XHRs

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

+23-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import DuckDBWasm from './duckdb-eh.js';
22
import { DuckDBBrowserBindings } from './bindings_browser_base';
33
import { DuckDBModule } from './duckdb_module';
44
import { DuckDBRuntime } from './runtime';
5-
import { Logger } from '../log';
5+
import { LogEvent, LogLevel, LogOrigin, LogTopic, Logger } from '../log';
66

77
/** DuckDB bindings for the browser */
88
export class DuckDB extends DuckDBBrowserBindings {
@@ -17,12 +17,28 @@ export class DuckDB extends DuckDBBrowserBindings {
1717
}
1818

1919
/** Instantiate the bindings */
20-
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-
});
20+
protected async instantiateImpl(moduleOverrides: Partial<DuckDBModule>): Promise<DuckDBModule> {
21+
try{
22+
const wasm = this.instantiateWasm.bind(this);
23+
const locateFile = this.locateFile.bind(this);
24+
25+
return await DuckDBWasm({
26+
...moduleOverrides,
27+
instantiateWasm: wasm,
28+
locateFile: locateFile,
29+
});
30+
} catch (error : any) {
31+
this.logger.log({
32+
timestamp: new Date(),
33+
level: LogLevel.ERROR,
34+
origin: LogOrigin.BINDINGS,
35+
topic: LogTopic.INSTANTIATE,
36+
event: LogEvent.ERROR,
37+
value: 'Failed to instantiate WASM: ' + error,
38+
});
39+
40+
throw error;
41+
}
2642
}
2743
}
2844

0 commit comments

Comments
 (0)