(logPath = path.join(os.homedir(), '.codex', 'log', 'codex-tui.log'), i18n = createI18n())
| 20844 | } |
| 20845 | |
| 20846 | function 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 | |
| 20874 | function truncateUserError(message, limit = 180) { |
| 20875 | const normalized = String(message ?? '').replace(/\s+/g, ' ').trim(); |
no test coverage detected