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 % nix_code.errLine->errLineOfCode
<< endl; << endl;
// error arrows for the column range. // error arrows for the column range.
if (nix_code.errLine->columnRange.has_value()) 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; int dashwidth = errwidth - 3 ? 3 : 80 - ndl;
string dashes; string dashes;
@ -110,9 +108,9 @@ void print_error(ErrorInfo &einfo)
% prefix % prefix
% level_string % level_string
% "---" % "---"
% einfo.errName % einfo.name
% dashes % dashes
% einfo.toolName % einfo.program
<< endl; << endl;
// filename. // filename.

View file

@ -39,13 +39,40 @@ class NixCode {
class ErrorInfo { class ErrorInfo {
public: public:
ErrLevel level; ErrLevel level;
string errName; string name;
string description; string description;
string toolName; string program;
optional<NixCode> nixCode; optional<NixCode> nixCode;
string hint; 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); string showErrLine(ErrLine &errLine);
void print_code_lines(string &prefix, NixCode &nix_code); void print_code_lines(string &prefix, NixCode &nix_code);

View file

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