mirror of
https://github.com/NixOS/nix
synced 2025-06-25 14:51:16 +02:00
Cleanup fmt.hh
When I started contributing to Nix, I found the mix of definitions and names in `fmt.hh` to be rather confusing, especially the small difference between `hintfmt` and `hintformat`. I've renamed many classes and added documentation to most definitions. - `formatHelper` is no longer exported. - `fmt`'s documentation is now with `fmt` rather than (misleadingly) above `formatHelper`. - `yellowtxt` is renamed to `Magenta`. `yellowtxt` wraps its value with `ANSI_WARNING`, but `ANSI_WARNING` has been equal to `ANSI_MAGENTA` for a long time. Now the name is updated. - `normaltxt` is renamed to `Uncolored`. - `hintfmt` has been merged into `hintformat` as extra constructor functions. - `hintformat` has been renamed to `hintfmt`. - The single-argument `hintformat(std::string)` constructor has been renamed to a static member `hintformat::interpolate` to avoid pitfalls with using user-generated strings as format strings.
This commit is contained in:
parent
1ba9780cf5
commit
149bd63afb
14 changed files with 135 additions and 80 deletions
|
@ -63,7 +63,7 @@ void printCodeLines(std::ostream & out,
|
|||
|
||||
struct Trace {
|
||||
std::shared_ptr<Pos> pos;
|
||||
hintformat hint;
|
||||
hintfmt hint;
|
||||
bool frame;
|
||||
};
|
||||
|
||||
|
@ -74,7 +74,7 @@ inline bool operator>=(const Trace& lhs, const Trace& rhs);
|
|||
|
||||
struct ErrorInfo {
|
||||
Verbosity level;
|
||||
hintformat msg;
|
||||
hintfmt msg;
|
||||
std::shared_ptr<Pos> pos;
|
||||
std::list<Trace> traces;
|
||||
|
||||
|
@ -126,7 +126,7 @@ public:
|
|||
: err { .level = lvlError, .msg = hintfmt(args...), .suggestions = sug }
|
||||
{ }
|
||||
|
||||
BaseError(hintformat hint)
|
||||
BaseError(hintfmt hint)
|
||||
: err { .level = lvlError, .msg = hint }
|
||||
{ }
|
||||
|
||||
|
@ -162,7 +162,7 @@ public:
|
|||
addTrace(std::move(e), hintfmt(std::string(fs), args...));
|
||||
}
|
||||
|
||||
void addTrace(std::shared_ptr<Pos> && e, hintformat hint, bool frame = false);
|
||||
void addTrace(std::shared_ptr<Pos> && e, hintfmt hint, bool frame = false);
|
||||
|
||||
bool hasTrace() const { return !err.traces.empty(); }
|
||||
|
||||
|
@ -215,7 +215,7 @@ public:
|
|||
: SystemError(""), errNo(errNo)
|
||||
{
|
||||
auto hf = hintfmt(args...);
|
||||
err.msg = hintfmt("%1%: %2%", normaltxt(hf.str()), strerror(errNo));
|
||||
err.msg = hintfmt("%1%: %2%", Uncolored(hf.str()), strerror(errNo));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue