Skip to content

Commit 607570a

Browse files
committed
cli(errors): improve diagnostic clarity and error UX
- Make compiler and runtime errors concise and focused - Add short, actionable hints instead of verbose dumps - Normalize memory/lifetime/ownership error rules - Clean up sanitizer output (signal over noise) - Keep code frames as the primary debugging context Goal: professional, readable diagnostics for real-world C++ code
1 parent 254140b commit 607570a

14 files changed

Lines changed: 957 additions & 1062 deletions

src/ErrorHandler.cpp

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -114,30 +114,24 @@ namespace
114114
const std::string &msg = err.message;
115115
const bool verbose = hints_verbose_enabled();
116116

117-
auto printHintHeader = []()
117+
auto h = [](const std::string &s)
118118
{
119119
std::cerr << "\n"
120-
<< YELLOW << "Hint:" << RESET << " ";
120+
<< YELLOW << "hint: " << RESET << s << "\n";
121121
};
122122

123123
if (msg.find("use of undeclared identifier 'std'") != std::string::npos)
124124
{
125-
printHintHeader();
126-
std::cerr << "The C++ standard library namespace `std` is not visible here.\n"
127-
<< GRAY
128-
<< "Fix:\n"
129-
<< " #include <iostream>\n"
130-
<< RESET;
125+
h("std is not visible here (include the required standard header)");
126+
if (verbose)
127+
std::cerr << GRAY << "e.g. #include <iostream>\n"
128+
<< RESET;
131129
return;
132130
}
133131

134132
if (msg.find("expected ';'") != std::string::npos)
135133
{
136-
printHintHeader();
137-
std::cerr << "A ';' is missing at this location.\n"
138-
<< GRAY
139-
<< "Check the previous line.\n"
140-
<< RESET;
134+
h("missing ';' (often the previous line)");
141135
return;
142136
}
143137

@@ -149,33 +143,14 @@ namespace
149143

150144
if (isVixJson)
151145
{
152-
printHintHeader();
153-
std::cerr
154-
<< "Response::json() expects ONE JSON object. You passed (key, value).\n"
155-
<< GRAY
156-
<< "Did you mean:\n"
157-
<< " res.json({\"message\", \"Hello, world\"});\n"
158-
<< RESET;
159-
146+
h("Response::json() expects one JSON value (not key,value)");
160147
if (verbose)
161-
{
162-
std::cerr
163-
<< GRAY
164-
<< "\nOther valid forms:\n"
165-
<< " res.json({ vix::json::kv(\"message\", \"Hello, world\") });\n"
166-
<< " return vix::json::o(\"message\", \"Hello, world\");\n"
167-
<< "\nWhy:\n"
168-
<< " json() accepts a JSON container/value (Vix tokens/builders), not two separate strings.\n"
169-
<< RESET;
170-
}
148+
std::cerr << GRAY << "e.g. res.json({\"message\", \"Hello\"});\n"
149+
<< RESET;
171150
return;
172151
}
173152

174-
printHintHeader();
175-
std::cerr << "The function call does not match any known overload.\n"
176-
<< GRAY
177-
<< "Check argument types and qualifiers.\n"
178-
<< RESET;
153+
h("no matching overload (check argument types and qualifiers)");
179154
return;
180155
}
181156
}

0 commit comments

Comments
 (0)