MCPcopy
hub / github.com/simstudioai/sim / extractCompilationErrors

Function extractCompilationErrors

apps/sim/app/api/tools/latex/route.ts:148–164  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

146 * context) from the compiler log files returned by the compile service.
147 */
148function 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

Callers 1

Calls 3

truncateFunction · 0.90
joinMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected