Skip to content

Commit 74d04d6

Browse files
leshniakclaude
andcommitted
fix: improve diagnostic logging for probe and all heal paths
- Probe start: logInfo when tab becomes visible and probe begins - Probe healthy: logInfo confirming connection is healthy - Probe stale: logAlert with error details when stale connection detected - Heal attempts/success/exhaustion/non-recoverable: same as Expensify#780 - Updated test assertions to match new log messages and levels Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent a4ebed8 commit 74d04d6

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

lib/storage/providers/IDBKeyValProvider/createStore.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,19 @@ function createStore(dbName: string, storeName: string): UseStore {
140140
return;
141141
}
142142

143+
Logger.logInfo('IDB visibilitychange probe: tab became visible, checking connection health', {dbName, storeName});
144+
143145
const probePromise = dbp;
144146

145147
const dropCacheIfStale = (error: unknown) => {
146148
if (dbp !== probePromise || !isStaleConnectionError(error)) {
147149
return;
148150
}
149-
Logger.logInfo('IDB visibilitychange probe: connection lost, dropping cached connection', {dbName, storeName});
151+
Logger.logAlert('IDB visibilitychange probe: stale connection detected, dropping cached connection', {
152+
dbName,
153+
storeName,
154+
errorMessage: error instanceof Error ? error.message : String(error),
155+
});
150156
dbp = undefined;
151157
};
152158

@@ -161,6 +167,7 @@ function createStore(dbName: string, storeName: string): UseStore {
161167
req.onerror = () => {
162168
dropCacheIfStale(req.error);
163169
};
170+
Logger.logInfo('IDB visibilitychange probe: connection is healthy', {dbName, storeName});
164171
} catch (error) {
165172
dropCacheIfStale(error);
166173
}

tests/unit/storage/providers/createStoreTest.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ describe('createStore', () => {
594594

595595
const result = await store('readonly', (s) => IDB.promisifyRequest(s.get('key1')));
596596
expect(result).toBe('value');
597-
expect(logInfoSpy).toHaveBeenCalledWith('IDB visibilitychange probe: connection lost, dropping cached connection', expect.objectContaining({dbName: expect.any(String)}));
597+
expect(logAlertSpy).toHaveBeenCalledWith(expect.stringContaining('IDB visibilitychange probe: stale connection detected'), expect.objectContaining({dbName: expect.any(String)}));
598598
});
599599

600600
it('should not probe when no connection exists yet', async () => {
@@ -629,7 +629,9 @@ describe('createStore', () => {
629629

630630
const result = await store('readonly', (s) => IDB.promisifyRequest(s.get('key1')));
631631
expect(result).toBe('value');
632-
expect(logInfoSpy).not.toHaveBeenCalledWith(expect.stringContaining('visibilitychange probe'), expect.anything());
632+
// Probe ran but found healthy connection — no stale connection alert
633+
expect(logAlertSpy).not.toHaveBeenCalledWith(expect.stringContaining('stale connection detected'), expect.anything());
634+
expect(logInfoSpy).toHaveBeenCalledWith(expect.stringContaining('connection is healthy'), expect.anything());
633635
});
634636

635637
it('should drop dbp when probe throws InvalidStateError', async () => {
@@ -662,7 +664,7 @@ describe('createStore', () => {
662664

663665
const result = await store('readonly', (s) => IDB.promisifyRequest(s.get('key1')));
664666
expect(result).toBe('value');
665-
expect(logInfoSpy).toHaveBeenCalledWith('IDB visibilitychange probe: connection lost, dropping cached connection', expect.objectContaining({dbName: expect.any(String)}));
667+
expect(logAlertSpy).toHaveBeenCalledWith(expect.stringContaining('IDB visibilitychange probe: stale connection detected'), expect.objectContaining({dbName: expect.any(String)}));
666668
});
667669
});
668670
});

0 commit comments

Comments
 (0)