UNPKG

@lunora/cli

Version:

The Lunora CLI: init, dev, deploy, codegen, run, reset, and migrate commands

32 lines (29 loc) 1.29 kB
import { findLunoraSolution } from '@lunora/codegen'; import { VisulimaError, renderError } from '@visulima/error'; const flattenSolutionBody = (solution) => solution.body.split("\n").filter((line) => !line.startsWith("```")).join("\n").replaceAll(/\*\*(.+?)\*\*/gu, "$1").replaceAll(/`([^`]+)`/gu, "$1"); const NO_STACK = { filterStacktrace: () => false, hideErrorCodeView: true }; const renderCodegenFailure = (error, reason) => { const message = error instanceof Error ? error.message : String(error); const solution = findLunoraSolution(message); const rendered = new VisulimaError({ hint: solution ? [solution.header, "", flattenSolutionBody(solution)] : void 0, message: reason === void 0 ? `codegen failed: ${message}` : `codegen failed (${reason}): ${message}`, name: "CodegenError" }); rendered.stack = ""; return renderError(rendered, NO_STACK); }; const renderCodegenHint = (message) => { const solution = findLunoraSolution(message); if (solution === void 0) { return void 0; } const rendered = new VisulimaError({ hint: [flattenSolutionBody(solution)], message: solution.header, name: "Hint" }); rendered.stack = ""; return renderError(rendered, NO_STACK); }; export { renderCodegenHint as a, renderCodegenFailure as r };