File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515// and DML statements are rejected up front for defence in depth.
1616// ============================================================
1717
18+ // MUST be first — polyfills browser globals that sql.js reads at init.
19+ import './polyfill.js' ;
1820import initSqlJs from 'sql.js' ;
1921
2022// Bundled at build time via wrangler.toml [[rules]].
@@ -235,8 +237,9 @@ export default {
235237 }
236238 } ) ;
237239 } catch ( e ) {
238- console . error ( 'chat error:' , e ) ;
239- return jsonError ( e . message || 'Internal error' , 500 , env ) ;
240+ console . error ( 'chat error:' , e ?. stack || e ) ;
241+ const detail = e ?. stack ? `${ e . message } \n${ e . stack } ` : ( e ?. message || String ( e ) ) ;
242+ return jsonError ( detail , 500 , env ) ;
240243 }
241244 }
242245} ;
Original file line number Diff line number Diff line change 1+ // Workers don't expose `location` or `document` — sql.js (Emscripten)
2+ // reads both during WASM init to locate the .wasm file. We stub them
3+ // here so sql.js can finish initialising; the stub URL is never fetched
4+ // because the worker passes its own `instantiateWasm` callback.
5+ //
6+ // This file MUST be imported before `sql.js`. ES-module imports are
7+ // evaluated in source order for side-effect imports, so put this first.
8+
9+ if ( typeof globalThis . location === 'undefined' ) {
10+ globalThis . location = new URL ( 'https://localhost/' ) ;
11+ }
12+ if ( typeof globalThis . document === 'undefined' ) {
13+ globalThis . document = { currentScript : { src : 'https://localhost/' } } ;
14+ }
You can’t perform that action at this time.
0 commit comments