Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0003-headless-output FR-008
The mechanism of explain and translate (commons headless 0003-headless-outputFR-008): a problem shown with a stable code says how to read more about it, and a raw error of another tool (ssh, apt, git) that people meet often is recognized and given its plain cause and fix. The catalogue of codes, the patterns of raw errors and the guides are the program's own data; this module holds the rules for using them.
import { explainText, translator } from"./explain.ts";
constcatalogue= { "E001-DNS": { title: "A name did not resolve", what: "It did not.", why: "The network is down.", fix: "ping 1.1.1.1" } };
consttranslate=translator(catalogue, [[/Could not resolve host/, "E001-DNS"]]);
translate("curl: Could not resolve host: x")?.code; // "E001-DNS"explainText(catalogue, { program: "tool" }, "e001-dns").includes("Likely cause"); // true
typeExplanation= {
readonlytitle:string;
/** What happened, in plain words. */readonlywhat:string;
/** The likely cause. */readonlywhy:string;
/** The fix: what to do, with the exact command where there is one. */readonlyfix:string;
/** The guide that explains more, by its name: the program says where it is shown. */readonlydoc?:string;
};
One problem's explanation: what, why, the fix, and the guide.
Everything wrong with a catalogue and its patterns: a code that is not a code, an explanation with a blank field, a pattern that names a code the catalogue lacks.
A function that gives a known raw error its code and fix, or undefined where the error is not known (it is then shown as it is). The first pattern that matches wins.
typeExplanation= {
readonlytitle:string;
/** What happened, in plain words. */readonlywhat:string;
/** The likely cause. */readonlywhy:string;
/** The fix: what to do, with the exact command where there is one. */readonlyfix:string;
/** The guide that explains more, by its name: the program says where it is shown. */readonlydoc?:string;
};
One problem's explanation: what, why, the fix, and the guide.
Everything wrong with a catalogue and its patterns: a code that is not a code, an explanation with a blank field, a pattern that names a code the catalogue lacks.
A function that gives a known raw error its code and fix, or undefined where the error is not known (it is then shown as it is). The first pattern that matches wins.