MCPcopy Create free account
hub / github.com/Noumena-Network/code / errorHandler

Function errorHandler

src/cli/handlers/ant.ts:648–689  ·  view source on GitHub ↗
(index?: number)

Source from the content-addressed store, hash-verified

646}
647
648export 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
691export async function exportHandler(
692 source: string,

Callers 1

runFunction · 0.85

Calls 11

parseJSONLFunction · 0.90
listErrorLogFilesFunction · 0.85
writeToStdoutFunction · 0.85
gracefulShutdownFunction · 0.85
formatBytesFunction · 0.85
normalizeSelectionIndexFunction · 0.85
readFileFunction · 0.85
writeJsonFunction · 0.85
writeToStderrFunction · 0.85
formatTimestampFunction · 0.70
errorMessageFunction · 0.50

Tested by

no test coverage detected