MCPcopy Create free account
hub / github.com/ForestHubAI/edge-agents / validateCommand

Function validateCommand

ts/workflow-cli/cli/validate.ts:18–58  ·  view source on GitHub ↗
(filePath?: string)

Source from the content-addressed store, hash-verified

16 * errors were found, 0 otherwise.
17 */
18export async function validateCommand(filePath?: string): Promise<void> {
19 if (!filePath) {
20 process.stderr.write("Usage: fh-workflow validate <file.json>\n");
21 process.exit(1);
22 }
23
24 const abs = path.resolve(process.cwd(), filePath);
25 let raw: string;
26 try {
27 raw = await fs.readFile(abs, "utf-8");
28 } catch (err: unknown) {
29 const code = (err as NodeJS.ErrnoException).code;
30 if (code === "ENOENT") {
31 process.stderr.write(`File not found: ${abs}\n`);
32 process.exit(1);
33 }
34 throw err;
35 }
36
37 let parsed: unknown;
38 try {
39 parsed = JSON.parse(raw);
40 } catch (err) {
41 process.stderr.write(`Invalid JSON: ${err instanceof Error ? err.message : String(err)}\n`);
42 process.exit(1);
43 }
44
45 let workflow: ApiWorkflow;
46 try {
47 workflow = migrate(parsed);
48 } catch (err) {
49 process.stderr.write(`${err instanceof Error ? err.message : String(err)}\n`);
50 process.exit(1);
51 }
52
53 const result = validateWorkflow(workflow);
54
55 printReport(abs, result);
56
57 if (result.totalErrors > 0) process.exit(1);
58}
59
60function printReport(file: string, result: ValidationResult): void {
61 const out = process.stdout;

Callers 1

index.tsFile · 0.90

Calls 4

migrateFunction · 0.90
validateWorkflowFunction · 0.90
printReportFunction · 0.85
writeMethod · 0.80

Tested by

no test coverage detected