diff --git a/packages/php-wasm/logger/src/lib/logger.ts b/packages/php-wasm/logger/src/lib/logger.ts index e3908e9cdf..1757f69891 100644 --- a/packages/php-wasm/logger/src/lib/logger.ts +++ b/packages/php-wasm/logger/src/lib/logger.ts @@ -127,6 +127,7 @@ export class Logger extends EventTarget { new CustomEvent(this.fatalErrorEvent, { detail: { logs: this.getLogs(), + source: event.source, }, }) ); diff --git a/packages/php-wasm/universal/src/lib/base-php.ts b/packages/php-wasm/universal/src/lib/base-php.ts index 03fdaa202a..2a6568ba8f 100644 --- a/packages/php-wasm/universal/src/lib/base-php.ts +++ b/packages/php-wasm/universal/src/lib/base-php.ts @@ -288,6 +288,8 @@ export abstract class BasePHP implements IsomorphicLocalPHP { ); // @ts-ignore error.output = output; + // @ts-ignore + error.source = 'request'; console.error(error); throw error; } @@ -296,6 +298,8 @@ export abstract class BasePHP implements IsomorphicLocalPHP { this.dispatchEvent({ type: 'request.error', error: e as Error, + // Distinguish between PHP request and PHP-wasm errors + source: (e as any).source ?? 'php-wasm', }); throw e; } finally { diff --git a/packages/php-wasm/universal/src/lib/universal-php.ts b/packages/php-wasm/universal/src/lib/universal-php.ts index dee30b2ae4..1bbc2b7757 100644 --- a/packages/php-wasm/universal/src/lib/universal-php.ts +++ b/packages/php-wasm/universal/src/lib/universal-php.ts @@ -14,6 +14,7 @@ export interface PHPRequestEndEvent { export interface PHPRequestErrorEvent { type: 'request.error'; error: Error; + source?: 'request' | 'php-wasm'; } /** diff --git a/packages/playground/website/src/components/error-report-modal/index.tsx b/packages/playground/website/src/components/error-report-modal/index.tsx index dfb0615942..6c9e5c3f2e 100644 --- a/packages/playground/website/src/components/error-report-modal/index.tsx +++ b/packages/playground/website/src/components/error-report-modal/index.tsx @@ -16,10 +16,13 @@ export function ErrorReportModal() { useEffect(() => { addFatalErrorListener(logger, (e) => { - setShowModal(true); - setText(''); - setLogs((e as CustomEvent).detail.logs.join('')); - setUrl(window.location.href); + const error = e as CustomEvent; + if (error.detail?.source === 'php-wasm') { + setShowModal(true); + setText(''); + setLogs(error.detail.logs.join('')); + setUrl(window.location.href); + } }); }, []);