Skip to content

Commit 347c2fa

Browse files
committed
fix bugs
1 parent 0f194aa commit 347c2fa

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

sdk/highlight-run/src/client/utils/sessionStorage/highlightSession.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
getPersistentStorage,
88
} from '../storage'
99
import { SESSION_STORAGE_KEYS } from './sessionStorageKeys'
10+
import { internalLogOnce } from '../../../sdk/util'
1011

1112
export type SessionData = {
1213
sessionSecureID: string
@@ -107,11 +108,31 @@ function pruneSessionData(keepKey: string): void {
107108
for (let i = getPersistentStorage().length - 1; i >= 0; i--) {
108109
const key = getPersistentStorage().key(i)
109110
if (key && key.startsWith(prefix) && key !== keepKey) {
110-
const sessionData = JSON.parse(getItem(key) || '{}') as SessionData
111-
if (
112-
sessionData.lastPushTime &&
113-
Date.now() - sessionData.lastPushTime >= SESSION_PUSH_THRESHOLD
114-
) {
111+
try {
112+
const sessionData = JSON.parse(
113+
getItem(key) || '{}',
114+
) as SessionData
115+
if (
116+
sessionData.lastPushTime &&
117+
Date.now() - sessionData.lastPushTime >=
118+
SESSION_PUSH_THRESHOLD
119+
) {
120+
internalLogOnce(
121+
'highlightSession',
122+
'pruneSessionData',
123+
'debug',
124+
`removing session data for stale key ${key}`,
125+
)
126+
removeItem(key)
127+
}
128+
} catch (e) {
129+
internalLogOnce(
130+
'highlightSession',
131+
'pruneSessionData',
132+
'error',
133+
`failed to parse session data for key ${key}`,
134+
e,
135+
)
115136
removeItem(key)
116137
}
117138
}

0 commit comments

Comments
 (0)