Skip to content

Commit e8c7452

Browse files
committed
fix: add runtime type checks and post-filter guard in readLocalEventPlanRich
- Use a runtime string type guard instead of unsafe `as string` casts so non-string field values (e.g. numbers) fall through to the `??` default instead of surviving as non-strings and crashing on `.trim()`. - Check filtered callsites array length before assignment to avoid returning events with an empty `callsites: []` array.
1 parent ee14860 commit e8c7452

1 file changed

Lines changed: 15 additions & 9 deletions

File tree

src/lib/event-plan-parser.ts

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,19 +209,22 @@ export function readLocalEventPlanRich(installDir: string): Array<{
209209

210210
if (!Array.isArray(parsed)) return [];
211211

212+
const str = (v: unknown): string | undefined =>
213+
typeof v === 'string' ? v : undefined;
214+
212215
return (parsed as Array<Record<string, unknown>>)
213216
.map((e) => {
214217
const name =
215-
(e.name as string) ??
216-
(e.event as string) ??
217-
(e.eventName as string) ??
218-
(e.event_name as string) ??
218+
str(e.name) ??
219+
str(e.event) ??
220+
str(e.eventName) ??
221+
str(e.event_name) ??
219222
'';
220223
const description =
221-
(e.description as string) ??
222-
(e.event_description as string) ??
223-
(e.eventDescription as string) ??
224-
(e.eventDescriptionAndReasoning as string) ??
224+
str(e.description) ??
225+
str(e.event_description) ??
226+
str(e.eventDescription) ??
227+
str(e.eventDescriptionAndReasoning) ??
225228
'';
226229
const result: {
227230
name: string;
@@ -232,9 +235,12 @@ export function readLocalEventPlanRich(installDir: string): Array<{
232235
description,
233236
};
234237
if (Array.isArray(e.callsites) && e.callsites.length > 0) {
235-
result.callsites = (
238+
const filtered = (
236239
e.callsites as Array<{ filePath: string; anchor?: string }>
237240
).filter((c) => c && typeof c.filePath === 'string');
241+
if (filtered.length > 0) {
242+
result.callsites = filtered;
243+
}
238244
}
239245
return result;
240246
})

0 commit comments

Comments
 (0)