This commit is contained in:
Ben Burdette 2020-03-24 09:18:23 -06:00
parent aadd59d005
commit 4171ab4bbd
3 changed files with 39 additions and 9 deletions

View File

@ -41,8 +41,6 @@ void print_code_lines(string &prefix, NixCode &nix_code)
% nix_code.errLine->errLineOfCode
<< endl;
// error arrows for the column range.
if (nix_code.errLine->columnRange.has_value())
{
@ -98,7 +96,7 @@ void print_error(ErrorInfo &einfo)
}
}
int ndl = level_string.length() + 3 + einfo.errName.length() + einfo.toolName.length();
int ndl = level_string.length() + 3 + einfo.name.length() + einfo.program.length();
int dashwidth = errwidth - 3 ? 3 : 80 - ndl;
string dashes;
@ -110,9 +108,9 @@ void print_error(ErrorInfo &einfo)
% prefix
% level_string
% "---"
% einfo.errName
% einfo.name
% dashes
% einfo.toolName
% einfo.program
<< endl;
// filename.

View File

@ -39,13 +39,40 @@ class NixCode {
class ErrorInfo {
public:
ErrLevel level;
string errName;
string name;
string description;
string toolName;
string program;
optional<NixCode> nixCode;
string hint;
ErrorInfo& GetEI() { return *this; }
};
template <class T>
class AddName : private T
{
public:
T& name(const std::string &name){
GetEI().name = name;
return *this;
}
protected:
ErrorInfo& GetEI() { return T::GetEI(); }
};
template <class T>
class AddDescription : private T
{
public:
T& description(const std::string &description){
GetEI().description = description;
return *this;
}
protected:
ErrorInfo& GetEI() { return T::GetEI(); }
};
typedef AddName<AddDescription<ErrorInfo>> StandardError;
string showErrLine(ErrLine &errLine);
void print_code_lines(string &prefix, NixCode &nix_code);

View File

@ -24,13 +24,18 @@ using namespace nix;
ErrorInfo generic;
generic.level = elError;
generic.errName = "error name";
generic.name = "error name";
generic.description = "general error description";
generic.toolName = "nixtool.exe";
generic.program = "nixtool.exe";
generic.nixCode = nixcode;
print_error(generic);
StandardError standardError;
print_error(standardError.name("blah").description("blah"));
return 0;
}