Skip to content

Commit

Permalink
fix(types): fix type cache crash
Browse files Browse the repository at this point in the history
There's some kind of weird race condition or something where the strict null check fails but then returns an undefined object. 

See firebase/genkit#972 for details on how to reproduce.

```
  name: 'TypeError',
  message: "Cannot destructure property 'shape' of 'this._getCached(...)' as it is undefined.",
  stack: "TypeError: Cannot destructure property 'shape' of 'this._getCached(...)' as it is undefined.\n" +
    '    at ZodObject._parse (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:1848:17)\n' +
    '    at ZodObject._parseSync (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:146:29)\n' +
    '    at /Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:1711:29\n' +
    '    at Array.map (<anonymous>)\n' +
    '    at ZodArray._parse (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:1710:38)\n' +
    '    at ZodObject._parse (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:1864:37)\n' +
    '    at ZodObject._parseSync (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:146:29)\n' +
    '    at ZodObject.safeParse (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:176:29)\n' +
    '    at ZodObject.parse (/Users/fuego/Documents/development/gemineye-server/node_modules/zod/lib/types.js:157:29)\n' +
    '    at /Users/fuego/Documents/development/gemineye-server/node_modules/@genkit-ai/flow/lib/flow.js:522:55',
```
  • Loading branch information
odbol authored Nov 7, 2024
1 parent f487d74 commit f281576
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2421,7 +2421,7 @@ export class ZodObject<
private _cached: { shape: T; keys: string[] } | null = null;

_getCached(): { shape: T; keys: string[] } {
if (this._cached !== null) return this._cached;
if (this._cached) return this._cached;
const shape = this._def.shape();
const keys = util.objectKeys(shape);
return (this._cached = { shape, keys });
Expand Down

0 comments on commit f281576

Please sign in to comment.