* Extracts TeX error lines (lines starting with `!`, each with two lines of * context) from the compiler log files returned by the compile service.
(logFiles: unknown)
| 146 | * context) from the compiler log files returned by the compile service. |
| 147 | */ |
| 148 | function extractCompilationErrors(logFiles: unknown): string | undefined { |
| 149 | if (typeof logFiles !== 'object' || logFiles === null) return undefined |
| 150 | |
| 151 | const snippets: string[] = [] |
| 152 | for (const log of Object.values(logFiles)) { |
| 153 | if (typeof log !== 'string') continue |
| 154 | const lines = log.split('\n') |
| 155 | for (let i = 0; i < lines.length; i++) { |
| 156 | if (lines[i].startsWith('!')) { |
| 157 | snippets.push(lines.slice(i, i + 3).join('\n')) |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if (snippets.length === 0) return undefined |
| 163 | return truncate([...new Set(snippets)].join('\n\n'), MAX_ERROR_MESSAGE_CHARS) |
| 164 | } |
| 165 | |
| 166 | /** |
| 167 | * Maps a failed compile-service response to a JSON error response: 422 with |
no test coverage detected