Skip to content

fix: add defensive optional chaining for remaining .info.time.created accesses#5

Merged
Plutarch01 merged 2 commits intoPlutarch01:masterfrom
Milofax:fix/malformed-message-time-crash
Apr 9, 2026
Merged

fix: add defensive optional chaining for remaining .info.time.created accesses#5
Plutarch01 merged 2 commits intoPlutarch01:masterfrom
Milofax:fix/malformed-message-time-crash

Conversation

@Milofax
Copy link
Copy Markdown
Contributor

@Milofax Milofax commented Apr 8, 2026

Summary

  • Adds ?. optional chaining + ?? 0 fallback to all 13 remaining occurrences of .info.time.created across store.ts, store-artifacts.ts, and store-search.ts
  • Prevents TypeError: undefined is not an object crash in ensureSummaryGraphSync and related code paths when messages have malformed or missing info.time metadata

Problem

v0.13.2 introduced getValidMessageInfo() and filterValidConversationMessages() to guard upstream entry points (#4), but 13 downstream access sites still use bare property chains and crash when a malformed message slips through:

TypeError: undefined is not an object
  (evaluating 'archivedMessages.at(-1)?.info.time.created')
  at ensureSummaryGraphSync (store.js)
  at transformMessages (store.js)

Changes

File Sites Fixed
src/store.ts 7 — diagnoseSummarySession, shouldSyncDerived ×3, buildArchivedSignature, ensureSummaryGraphSync ×2
src/store-artifacts.ts 3 — externalizeMessage ×2, writeStoredSession
src/store-search.ts 3 — searchSync, rebuildSessionFtsRowsSync, replaceMessageSearchRowSync

Verification

  • npm run typecheck
  • npm run lint
  • npm run build
  • npm test168/168 pass
  • Zero remaining bare .info.time.created patterns in source

Milofax and others added 2 commits April 8, 2026 22:01
All 13 remaining occurrences of `.info.time.created` across store.ts,
store-artifacts.ts, and store-search.ts crash with TypeError when a
message has malformed or missing `info.time` metadata.

v0.13.2 introduced `getValidMessageInfo()` and
`filterValidConversationMessages()` to guard upstream entry points,
but 13 downstream access sites still use bare property chains.

Replace every bare `.info.time.created` access with
`.info?.time?.created ?? 0` so a single malformed message cannot
crash the entire plugin.

Reproducer: any session containing a message where `info.time` is
undefined triggers:
  TypeError: undefined is not an object
    (evaluating 'archivedMessages.at(-1)?.info.time.created')
    at ensureSummaryGraphSync
@Plutarch01 Plutarch01 merged commit ee029c2 into Plutarch01:master Apr 9, 2026
Plutarch01 pushed a commit that referenced this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants