mirror of
https://github.com/Kaelio/ktx.git
synced 2026-06-16 08:25:14 +02:00
20 lines
773 B
TypeScript
20 lines
773 B
TypeScript
import { readFile } from 'node:fs/promises';
|
|
import { parseIngestReportSnapshot, type IngestReportSnapshot } from '@ktx/context/ingest';
|
|
|
|
export async function readIngestReportSnapshotFile(reportFile: string): Promise<IngestReportSnapshot> {
|
|
const raw = await readFile(reportFile, 'utf-8');
|
|
let parsed: unknown;
|
|
try {
|
|
parsed = JSON.parse(raw);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
throw new Error(`Invalid JSON in ingest report file ${reportFile}: ${message}`);
|
|
}
|
|
|
|
try {
|
|
return parseIngestReportSnapshot(parsed);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : String(error);
|
|
throw new Error(`Invalid ingest report file ${reportFile}: ${message}`);
|
|
}
|
|
}
|