| 203 | } |
| 204 | |
| 205 | async function loadResultsMap(resultsFile: string): Promise<Map<string, QuestionResultRecord>> { |
| 206 | try { |
| 207 | const content = await readFile(resultsFile, "utf8"); |
| 208 | const map = new Map<string, QuestionResultRecord>(); |
| 209 | for (const line of content.split(/\r?\n/)) { |
| 210 | if (!line.trim()) continue; |
| 211 | const parsed = JSON.parse(line) as QuestionResultRecord; |
| 212 | map.set(parsed.question_id, parsed); |
| 213 | } |
| 214 | return map; |
| 215 | } catch (error) { |
| 216 | const typed = asError(error); |
| 217 | if ((typed as NodeJS.ErrnoException).code === "ENOENT") { |
| 218 | return new Map(); |
| 219 | } |
| 220 | throw typed; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | async function loadState(config: RunnerConfig): Promise<RunnerStateFile> { |
| 225 | if (!config.resume) { |