(index?: number)
| 646 | } |
| 647 | |
| 648 | export async function errorHandler(index?: number): Promise<void> { |
| 649 | try { |
| 650 | const files = await listErrorLogFiles() |
| 651 | if (files.length === 0) { |
| 652 | writeToStdout('No error logs found.\n') |
| 653 | await gracefulShutdown(0) |
| 654 | return |
| 655 | } |
| 656 | |
| 657 | if (typeof index === 'undefined' || Number.isNaN(index)) { |
| 658 | files.forEach((file, i) => { |
| 659 | writeToStdout( |
| 660 | `${String(i).padStart(3)} ${formatTimestamp(file.modified)} ${formatBytes(file.size)} ${file.name}\n`, |
| 661 | ) |
| 662 | }) |
| 663 | await gracefulShutdown(0) |
| 664 | return |
| 665 | } |
| 666 | |
| 667 | const normalized = normalizeSelectionIndex(index, files.length) |
| 668 | if (normalized === null) { |
| 669 | throw new Error(`No error log found for index ${index}.`) |
| 670 | } |
| 671 | |
| 672 | const file = files[normalized]! |
| 673 | const content = await readFile(file.fullPath, 'utf8') |
| 674 | const parsed = parseJSONL<unknown>(content) |
| 675 | if (parsed.length > 0) { |
| 676 | writeJson({ |
| 677 | path: file.fullPath, |
| 678 | modified: file.modified.toISOString(), |
| 679 | entries: parsed, |
| 680 | }) |
| 681 | } else { |
| 682 | writeToStdout(content.endsWith('\n') ? content : `${content}\n`) |
| 683 | } |
| 684 | await gracefulShutdown(0) |
| 685 | } catch (error) { |
| 686 | writeToStderr(`Failed to read error logs: ${errorMessage(error)}\n`) |
| 687 | await gracefulShutdown(1) |
| 688 | } |
| 689 | } |
| 690 | |
| 691 | export async function exportHandler( |
| 692 | source: string, |
no test coverage detected