forked from lix-project/lix
add some explanatory comments
This commit is contained in:
parent
9e7b89bf10
commit
5b3aefff85
|
@ -152,12 +152,14 @@ void printErrorInfo(ErrorInfo &einfo)
|
||||||
|
|
||||||
// lines of code.
|
// lines of code.
|
||||||
if (einfo.nixCode.has_value())
|
if (einfo.nixCode.has_value())
|
||||||
|
{
|
||||||
printCodeLines(prefix, *einfo.nixCode);
|
printCodeLines(prefix, *einfo.nixCode);
|
||||||
|
cout << prefix << endl;
|
||||||
|
}
|
||||||
|
|
||||||
// hint
|
// hint
|
||||||
if (einfo.hint.has_value())
|
if (einfo.hint.has_value())
|
||||||
{
|
{
|
||||||
cout << prefix << endl;
|
|
||||||
cout << prefix << *einfo.hint << endl;
|
cout << prefix << *einfo.hint << endl;
|
||||||
cout << prefix << endl;
|
cout << prefix << endl;
|
||||||
}
|
}
|
||||||
|
|
|
@ -257,6 +257,7 @@ typedef AddName<
|
||||||
AddDescription<
|
AddDescription<
|
||||||
AddHint<
|
AddHint<
|
||||||
EIError>>> ProgramError;
|
EIError>>> ProgramError;
|
||||||
|
|
||||||
typedef AddName<
|
typedef AddName<
|
||||||
AddDescription<
|
AddDescription<
|
||||||
AddHint<
|
AddHint<
|
||||||
|
@ -270,6 +271,7 @@ typedef AddName<
|
||||||
AddLOC<
|
AddLOC<
|
||||||
AddHint<
|
AddHint<
|
||||||
EIError>>>>>>> NixLangError;
|
EIError>>>>>>> NixLangError;
|
||||||
|
|
||||||
typedef AddName<
|
typedef AddName<
|
||||||
AddDescription<
|
AddDescription<
|
||||||
AddNixFile<
|
AddNixFile<
|
||||||
|
|
|
@ -8,26 +8,43 @@ using std::nullopt;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
using namespace nix;
|
using namespace nix;
|
||||||
|
|
||||||
|
// In each program where errors occur, this has to be set.
|
||||||
ErrorInfo::programName = optional("error-test");
|
ErrorInfo::programName = optional("error-test");
|
||||||
|
|
||||||
printErrorInfo(ProgramError()
|
// There are currently four error types -
|
||||||
|
// ProgramError, ProgramWarning, NixLangError, NixLangWarning.
|
||||||
|
// Each error type is created with a specific sequence of builder functions.
|
||||||
|
// Unlike with a constructor, each parameter is clearly named.
|
||||||
|
// If the sequence of function calls isn't followed, then there's a type error.
|
||||||
|
// This should make for a consistent look in the code when errors are created.
|
||||||
|
|
||||||
|
// ProgramError takes name, description, and an optional hint.
|
||||||
|
printErrorInfo(
|
||||||
|
ProgramError()
|
||||||
.name("name")
|
.name("name")
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.nohint()
|
.nohint()
|
||||||
);
|
);
|
||||||
|
|
||||||
printErrorInfo(ProgramWarning()
|
// ProgramWarning takes name, description, and an optional hint.
|
||||||
|
// The hint is in the form of a hintfmt class, which wraps boost::format(), and
|
||||||
|
// makes all the substituted text yellow.
|
||||||
|
printErrorInfo(
|
||||||
|
ProgramWarning()
|
||||||
.name("warning name")
|
.name("warning name")
|
||||||
.description("warning description")
|
.description("warning description")
|
||||||
.nohint()
|
.hint(hintfmt("there was a %1%") % "warning") // 'warning' will be yellow.
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// NixLangWarning adds nix file, line number, column range, and the lines of code
|
||||||
printErrorInfo(NixLangWarning()
|
// where a warning occurred.
|
||||||
|
printErrorInfo(
|
||||||
|
NixLangWarning()
|
||||||
.name("warning name")
|
.name("warning name")
|
||||||
.description("warning description")
|
.description("warning description")
|
||||||
.nixFile("myfile.nix")
|
.nixFile("myfile.nix")
|
||||||
|
@ -39,7 +56,9 @@ int main()
|
||||||
.hint(hintfmt("this hint has %1% templated %2%!!") % "yellow" % "values")
|
.hint(hintfmt("this hint has %1% templated %2%!!") % "yellow" % "values")
|
||||||
);
|
);
|
||||||
|
|
||||||
printErrorInfo(NixLangError()
|
// NixLangError is just the same as NixLangWarning, except for the Error flag.
|
||||||
|
printErrorInfo(
|
||||||
|
NixLangError()
|
||||||
.name("error name")
|
.name("error name")
|
||||||
.description("error description")
|
.description("error description")
|
||||||
.nixFile("myfile.nix")
|
.nixFile("myfile.nix")
|
||||||
|
|
Loading…
Reference in a new issue