diff --git a/src/__tests__/utils/pt9-import-error.test.ts b/src/__tests__/utils/pt9-import-error.test.ts index deebc0c9..90bc3b04 100644 --- a/src/__tests__/utils/pt9-import-error.test.ts +++ b/src/__tests__/utils/pt9-import-error.test.ts @@ -28,4 +28,12 @@ describe('isPt9TooLargeError', () => { expect(isPt9TooLargeError(new Error('boom'))).toBe(false); expect(isPt9TooLargeError(MARKER_MESSAGE)).toBe(false); }); + + it('rejects a platform error carrying no message instead of throwing', () => { + // Narrows as a platform error despite omitting the message the type declares as required. + const noMessage: unknown = { platformErrorVersion: 1 }; + + expect(() => isPt9TooLargeError(noMessage)).not.toThrow(); + expect(isPt9TooLargeError(noMessage)).toBe(false); + }); }); diff --git a/src/utils/pt9-import-error.ts b/src/utils/pt9-import-error.ts index fd21d31e..1b96cf86 100644 --- a/src/utils/pt9-import-error.ts +++ b/src/utils/pt9-import-error.ts @@ -13,6 +13,11 @@ const PT9_TOO_LARGE_MARKER = 'PT9 interlinear data is too large'; */ export function isPt9TooLargeError(error: unknown): boolean { if (isPlatformError(error)) - return error.code === 'RESOURCE_EXHAUSTED' || error.message.includes(PT9_TOO_LARGE_MARKER); + // The narrowing proves less than the type does: a value can satisfy it without carrying the + // declared message, and we want to answer rather than throw. + return ( + error.code === 'RESOURCE_EXHAUSTED' || + (typeof error.message === 'string' && error.message.includes(PT9_TOO_LARGE_MARKER)) + ); return error instanceof Error && error.message.includes(PT9_TOO_LARGE_MARKER); }