mirror of
https://github.com/NixOS/nix
synced 2025-06-26 20:01:15 +02:00
comment cleanup
This commit is contained in:
parent
ec449c8450
commit
55c96b64e4
2 changed files with 23 additions and 153 deletions
|
@ -11,15 +11,10 @@ int main()
|
|||
// In each program where errors occur, this has to be set.
|
||||
ErrorInfo::programName = std::optional("error-demo");
|
||||
|
||||
// There are currently four error types:
|
||||
// There are currently four constructor functions:
|
||||
//
|
||||
// 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(
|
||||
|
@ -33,68 +28,35 @@ int main()
|
|||
printErrorInfo(
|
||||
ErrorInfo::ProgramWarning("name",
|
||||
"warning description",
|
||||
std::optional(hintfmt("there was a %1%", "warning"))));
|
||||
|
||||
// printErrorInfo( ProgramWarning()
|
||||
// .name("warning name")
|
||||
// .description("warning description")
|
||||
// // the templated value, 'warning', is automatically colored yellow.
|
||||
// .hint(hintfmt("there was a %1%", "warning"))
|
||||
// );
|
||||
|
||||
/*
|
||||
// some invalid errors:
|
||||
|
||||
// type error: no hint function.
|
||||
ProgramError()
|
||||
.name("name")
|
||||
.description("error description");
|
||||
|
||||
// type error: description before name.
|
||||
ProgramError()
|
||||
.description("error description")
|
||||
.name("name")
|
||||
.nohint();
|
||||
|
||||
// type error: hint function with regular boost format, not special
|
||||
hintfmt. ProgramError() .description("error description") .name("name")
|
||||
.hint(format("there was a %1%") % "warning");
|
||||
*/
|
||||
std::optional(
|
||||
hintfmt("there was a %1%", "warning"))));
|
||||
|
||||
// NixLangWarning adds nix file, line number, column range, and the lines of
|
||||
// code where a warning occurred.
|
||||
|
||||
SymbolTable testTable;
|
||||
auto problem_symbol = testTable.create("problem");
|
||||
|
||||
printErrorInfo(ErrorInfo::NixLangWarning(
|
||||
"warning name",
|
||||
"warning description",
|
||||
Pos(problem_symbol, 40, 13),
|
||||
std::nullopt,
|
||||
"this is the problem line of code",
|
||||
std::nullopt,
|
||||
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
|
||||
|
||||
// // NixLangError is just the same as NixLangWarning, except for the Error
|
||||
// // flag.
|
||||
// printErrorInfo(NixLangError()
|
||||
// .name("error name")
|
||||
// .description("error description")
|
||||
// .pos(Pos(problem_symbol, 40, 13))
|
||||
// .linesOfCode(std::optional("previous line of code"),
|
||||
// "this is the problem line of code",
|
||||
// std::optional("next line of code"))
|
||||
// .hint(hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
|
||||
printErrorInfo(ErrorInfo::NixLangError(
|
||||
"error name",
|
||||
"error description",
|
||||
Pos(problem_symbol, 40, 13),
|
||||
std::optional("previous line of code"),
|
||||
"this is the problem line of code",
|
||||
std::optional("next line of code"),
|
||||
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
|
||||
printErrorInfo(
|
||||
ErrorInfo::NixLangWarning(
|
||||
"warning name",
|
||||
"warning description",
|
||||
Pos(problem_symbol, 40, 13),
|
||||
std::nullopt,
|
||||
"this is the problem line of code",
|
||||
std::nullopt,
|
||||
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
|
||||
|
||||
// NixLangError is just the same as NixLangWarning, except for the Error
|
||||
// flag.
|
||||
printErrorInfo(
|
||||
ErrorInfo::NixLangError(
|
||||
"error name",
|
||||
"error description",
|
||||
Pos(problem_symbol, 40, 13),
|
||||
std::optional("previous line of code"),
|
||||
"this is the problem line of code",
|
||||
std::optional("next line of code"),
|
||||
hintfmt("this hint has %1% templated %2%!!", "yellow", "values")));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue