UNPKG

baldrick-broth

Version:
33 lines (32 loc) 822 B
/** * Responsibilities: File I/O helpers for reading YAML documents. * - Reads and parses YAML, returning Result with structured errors */ import fs from 'node:fs/promises'; import YAML from 'yaml'; import { willFail } from './railway.js'; export const readYaml = async (filename) => { let content; try { content = await fs.readFile(filename, { encoding: 'utf8' }); } catch { return willFail({ message: `The yaml file cannot be found: ${filename}`, filename, }); } try { const value = YAML.parse(content); return { status: 'success', value, }; } catch { return willFail({ message: `The yaml file cannot be parsed: ${filename}`, filename, }); } };