Skip to content

Commit

Permalink
refactor: sync error too
Browse files Browse the repository at this point in the history
  • Loading branch information
PatrickJS committed May 13, 2024
1 parent 384fc80 commit 66be3ca
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions packages/qwik/src/qwikloader.ts
Expand Up @@ -101,20 +101,36 @@ export const qwikLoader = (
const symbol = url.hash[replace](/^#?([^?[|]*).*$/, '$1') || 'default';
const reqTime = performance.now();
let handler: any;
let error: Error | undefined;
let importError;
let syncHandlerError;
const isSync = qrl.startsWith('#');
if (isSync) {
handler = (container.qFuncs || [])[Number.parseInt(symbol)];
if (!handler) {
syncHandlerError = true;
error = new Error('sync handler error for symbol: ' + symbol);
}
} else {
const uri = url.href.split('#')[0];
try {
const module = import(/* @vite-ignore */ uri);
resolveContainer(container);
handler = (await module)[symbol];
} catch (error) {
emitEvent('qerror', { importError: true, error, symbol, uri });
} catch (err) {
importError = true;
error = err as Error;
}
}
if (!handler) {
const eventData = {
syncHandlerError,
importError,
error,
symbol,
href: url.href,
};
emitEvent('qerror', eventData);
// break out of the loop if handler is not found
break;
}
Expand Down

0 comments on commit 66be3ca

Please sign in to comment.