Skip to content

Commit 86b6f6c

Browse files
committed
fix: show warning when account persistence fails (closes #18)
- Changed silent DEBUG logging to visible WARN level - Added toast notification when persistence fails - Show storage path in error for diagnostics - Added try-catch to both manual OAuth flow paths
1 parent bf58b9f commit 86b6f6c

1 file changed

Lines changed: 39 additions & 10 deletions

File tree

index.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,12 +1069,23 @@ while (attempted.size < Math.max(1, accountCount)) {
10691069
};
10701070
}
10711071

1072-
if (useManualMode) {
1073-
const { pkce, url } = await createAuthorizationFlow();
1074-
return buildManualOAuthFlow(pkce, url, async (tokens) => {
1075-
await persistAccountPool([tokens], startFresh);
1076-
});
1072+
if (useManualMode) {
1073+
const { pkce, url } = await createAuthorizationFlow();
1074+
return buildManualOAuthFlow(pkce, url, async (tokens) => {
1075+
try {
1076+
await persistAccountPool([tokens], startFresh);
1077+
} catch (err) {
1078+
const storagePath = getStoragePath();
1079+
logWarn(`[${PLUGIN_NAME}] Failed to persist account to disk: ${(err as Error)?.message ?? String(err)}`);
1080+
logWarn(`Storage path: ${storagePath}`);
1081+
await showToast(
1082+
`Account authenticated but failed to save to disk. Storage path: ${storagePath}`,
1083+
"warning",
1084+
{ title: "Account Persistence Failed", duration: 10000 },
1085+
);
10771086
}
1087+
});
1088+
}
10781089

10791090
while (accounts.length < targetCount) {
10801091
logInfo(
@@ -1146,7 +1157,14 @@ while (attempted.size < Math.max(1, accountCount)) {
11461157
isFirstAccount && startFresh,
11471158
);
11481159
} catch (err) {
1149-
logDebug(`[${PLUGIN_NAME}] Failed to persist account pool: ${(err as Error)?.message ?? String(err)}`);
1160+
const storagePath = getStoragePath();
1161+
logWarn(`[${PLUGIN_NAME}] Failed to persist account to disk: ${(err as Error)?.message ?? String(err)}`);
1162+
logWarn(`Storage path: ${storagePath}`);
1163+
await showToast(
1164+
`Account authenticated but failed to save to disk. Storage path: ${storagePath}`,
1165+
"warning",
1166+
{ title: "Account Persistence Failed", duration: 10000 },
1167+
);
11501168
}
11511169

11521170
if (accounts.length >= ACCOUNT_LIMITS.MAX_ACCOUNTS) {
@@ -1184,13 +1202,24 @@ while (attempted.size < Math.max(1, accountCount)) {
11841202
};
11851203
},
11861204
},
1187-
{
1188-
label: AUTH_LABELS.OAUTH_MANUAL,
1189-
type: "oauth" as const,
1205+
{
1206+
label: AUTH_LABELS.OAUTH_MANUAL,
1207+
type: "oauth" as const,
11901208
authorize: async () => {
11911209
const { pkce, url } = await createAuthorizationFlow();
11921210
return buildManualOAuthFlow(pkce, url, async (tokens) => {
1193-
await persistAccountPool([tokens], false);
1211+
try {
1212+
await persistAccountPool([tokens], false);
1213+
} catch (err) {
1214+
const storagePath = getStoragePath();
1215+
logWarn(`[${PLUGIN_NAME}] Failed to persist account to disk: ${(err as Error)?.message ?? String(err)}`);
1216+
logWarn(`Storage path: ${storagePath}`);
1217+
await showToast(
1218+
`Account authenticated but failed to save to disk. Storage path: ${storagePath}`,
1219+
"warning",
1220+
{ title: "Account Persistence Failed", duration: 10000 },
1221+
);
1222+
}
11941223
});
11951224
},
11961225
},

0 commit comments

Comments
 (0)