UNPKG

mlld

Version:

mlld: a modular prompt scripting language

57 lines (53 loc) 1.62 kB
import { __name } from './chunk-OMKLS24H.mjs'; import fs from 'fs/promises'; import path from 'path'; async function captureError(error, source, filePath) { const id = await getNextCaptureId(); const dir = path.join("errors", "captured", id); await fs.mkdir(dir, { recursive: true }); await fs.writeFile(path.join(dir, "input.mld"), source); const context = { error: { message: error.message, name: error.name, stack: error.stack, location: error.location, found: error.found, expected: error.expected }, filePath, timestamp: (/* @__PURE__ */ new Date()).toISOString() }; await fs.writeFile(path.join(dir, "context.json"), JSON.stringify(context, null, 2)); await fs.copyFile(path.join("errors", "templates", "pattern.ts"), path.join(dir, "pattern.ts")); await fs.writeFile(path.join(dir, "example.md"), `# Error Pattern: ${id} ## Input \`\`\`mld ${source} \`\`\` ## Error \`\`\` ${error.message} \`\`\` `); return dir; } __name(captureError, "captureError"); async function getNextCaptureId() { const captureDir = path.join("errors", "captured"); try { await fs.access(captureDir); } catch { return "001"; } const entries = await fs.readdir(captureDir); const ids = entries.filter((e) => /^\d{3}$/.test(e)).map((e) => parseInt(e, 10)).sort((a, b) => b - a); const nextId = ids.length > 0 ? ids[0] + 1 : 1; return nextId.toString().padStart(3, "0"); } __name(getNextCaptureId, "getNextCaptureId"); export { captureError }; //# sourceMappingURL=capture-KPIII4FK.mjs.map //# sourceMappingURL=capture-KPIII4FK.mjs.map