MCPcopy Create free account
hub / github.com/Gan-Xing/CodexBridge / readRecentCodexRuntimeError

Function readRecentCodexRuntimeError

src/core/bridge_coordinator.ts:20846–20872  ·  view source on GitHub ↗
(logPath = path.join(os.homedir(), '.codex', 'log', 'codex-tui.log'), i18n = createI18n())

Source from the content-addressed store, hash-verified

20844}
20845
20846function readRecentCodexRuntimeError(logPath = path.join(os.homedir(), '.codex', 'log', 'codex-tui.log'), i18n = createI18n()) {
20847 try {
20848 const raw = fs.readFileSync(logPath, 'utf8');
20849 const lines = raw.trimEnd().split('\n').slice(-400);
20850 for (let index = lines.length - 1; index >= 0; index -= 1) {
20851 const line = lines[index];
20852 if (!line.includes('ERROR ')) {
20853 continue;
20854 }
20855 const next = lines[index + 1] ?? '';
20856 if (/refresh_token_reused/i.test(line) || /refresh_token_reused/i.test(next)) {
20857 return i18n.t('coordinator.codexAuth.refreshFailed');
20858 }
20859 if (/401 Unauthorized/i.test(line) || /401 Unauthorized/i.test(next)) {
20860 return i18n.t('coordinator.codexAuth.unauthorized');
20861 }
20862 const match = line.match(/ERROR\s+[^:]+:\s*(.+)$/);
20863 if (match?.[1]) {
20864 return truncateUserError(match[1]);
20865 }
20866 return truncateUserError(line);
20867 }
20868 } catch {
20869 return '';
20870 }
20871 return '';
20872}
20873
20874function truncateUserError(message, limit = 180) {
20875 const normalized = String(message ?? '').replace(/\s+/g, ' ').trim();

Callers 1

classifyTurnFailureFunction · 0.85

Calls 3

createI18nFunction · 0.85
truncateUserErrorFunction · 0.85
tMethod · 0.65

Tested by

no test coverage detected