Skip to content

Commit bd03e0f

Browse files
committed
fix(errors): refine diagnostics formatting and matching
2 parents ef96efd + f7e997c commit bd03e0f

7 files changed

Lines changed: 84 additions & 51 deletions

src/errors/RawLogDetectors.cpp

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,8 @@ namespace vix::cli::errors
11831183
rules.push_back(makeThreadJoinableRule());
11841184
rules.push_back(makeDataRaceRule());
11851185
rules.push_back(makeDeadlockRule());
1186-
rules.push_back(makeMutexMisuseRule());
11871186
rules.push_back(makeConditionVariableMisuseRule());
1187+
rules.push_back(makeMutexMisuseRule());
11881188
rules.push_back(makeFuturePromiseRule());
11891189
rules.push_back(makeThreadCreationFailureRule());
11901190
rules.push_back(makeDetachedThreadLifetimeRule());
@@ -1215,15 +1215,11 @@ namespace vix::cli::errors
12151215
if (handleRuntimePortAlreadyInUse(log, sourceFile))
12161216
return true;
12171217

1218-
// 2) C++ exceptions (your existing handler)
1219-
if (vix::cli::errors::rules::handleUncaughtException(log, sourceFile))
1220-
return true;
1221-
1222-
// 3) Typed UB (UBSan) MUST be early because it may also contain "runtime error:"
1218+
// 2) Typed UB (UBSan) MUST be early because it may also contain "runtime error:"
12231219
if (handleUBSanRuntimeError(log, sourceFile))
12241220
return true;
12251221

1226-
// 4) Typed allocator/memory families
1222+
// 3) Typed allocator/memory families
12271223
if (handleRuntimeAllocDeallocMismatch(log, sourceFile))
12281224
return true;
12291225
if (handleRuntimeDoubleFree(log, sourceFile))
@@ -1239,31 +1235,34 @@ namespace vix::cli::errors
12391235
if (handleRuntimeBufferOverflow(log, sourceFile))
12401236
return true;
12411237

1242-
// 5) Other common crashes & signals
1238+
// 4) Other common crashes & signals
12431239
if (handleRuntimeAssertionFailed(log, sourceFile))
12441240
return true;
12451241
if (handleRuntimeBadAllocOOM(log, sourceFile))
12461242
return true;
12471243

1248-
// 5.1) Modular runtime rules
1244+
// 5) Modular runtime rules
12491245
if (handleRuntimeRules(log, sourceFile))
12501246
return true;
12511247

1252-
// 6) Other sanitizers (LSan/TSan/MSan)
1248+
// 6) C++ exceptions fallback
1249+
if (vix::cli::errors::rules::handleUncaughtException(log, sourceFile))
1250+
return true;
1251+
1252+
// 7) Other sanitizers (LSan/TSan/MSan)
12531253
if (handleLeakSanitizer(log, sourceFile))
12541254
return true;
12551255
if (handleThreadSanitizer(log, sourceFile))
12561256
return true;
12571257
if (handleMemorySanitizer(log, sourceFile))
12581258
return true;
12591259

1260-
// 7) Generic sanitizer banner (last resort)
1260+
// 8) Generic sanitizer banner (last resort)
12611261
if (handleGenericSanitizerBanner(log, sourceFile))
12621262
return true;
12631263

12641264
return handleGenericRuntimeFallback(log, sourceFile);
12651265
}
1266-
12671266
} // namespace
12681267

12691268
bool RawLogDetectors::handleKnownRunFailure(

src/errors/runtime/MutexMisuseRule.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ namespace vix::cli::errors::runtime
3737
return icontains(log, "mutex") ||
3838
icontains(log, "resource deadlock avoided") ||
3939
icontains(log, "operation not permitted") ||
40-
icontains(log, "invalid argument") ||
41-
icontains(log, "pthread_mutex") ||
42-
icontains(log, "std::system_error");
40+
icontains(log, "pthread_mutex");
4341
}
4442

4543
bool handle(

src/errors/runtime/RuntimeRuleUtils.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,19 @@ namespace vix::cli::errors::runtime
122122
for (const auto &hintText : hints)
123123
{
124124
std::cerr << YELLOW
125-
<< "hint: " << hintText
126-
<< RESET << "\n";
125+
<< "hint: "
126+
<< RESET
127+
<< hintText
128+
<< "\n";
127129
}
128130

129131
if (!at.empty())
130132
{
131133
std::cerr << GREEN
132-
<< "at: " << at
133-
<< RESET << "\n";
134+
<< "at: "
135+
<< RESET
136+
<< at
137+
<< "\n";
134138
}
135139
}
136140
} // namespace vix::cli::errors::runtime

src/errors/template/DependentTypenameRule.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,30 @@ namespace vix::cli::errors::template_rules
8484
const std::string fileName = filePath.filename().string();
8585

8686
std::cerr << RED
87-
<< "error: missing typename before dependent type"
88-
<< RESET << "\n";
87+
<< "error: "
88+
<< RESET
89+
<< "missing typename before dependent type"
90+
<< "\n";
8991

9092
printCodeFrame(err, ctx);
9193

9294
std::cerr << YELLOW
93-
<< "hint: this type depends on a template parameter, so the compiler needs typename to know it is a type"
94-
<< RESET << "\n";
95+
<< "hint: "
96+
<< RESET
97+
<< "this type depends on a template parameter, so the compiler needs typename to know it is a type"
98+
<< "\n";
9599

96100
std::cerr << YELLOW
97-
<< "hint: write typename before names like T::value_type, T::iterator, or U::type when they refer to a type"
98-
<< RESET << "\n";
101+
<< "hint: "
102+
<< RESET
103+
<< "write typename before names like T::value_type, T::iterator, or U::type when they refer to a type"
104+
<< "\n";
99105

100106
std::cerr << GREEN
101-
<< "at: " << fileName << ":" << err.line << ":" << err.column
102-
<< RESET << "\n";
107+
<< "at: "
108+
<< RESET
109+
<< fileName << ":" << err.line << ":" << err.column
110+
<< "\n";
103111

104112
return true;
105113
}

src/errors/template/NoTypeNamedRule.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,30 @@ namespace vix::cli::errors::template_rules
8484
const std::string fileName = filePath.filename().string();
8585

8686
std::cerr << RED
87-
<< "error: type alias or nested type not found"
88-
<< RESET << "\n";
87+
<< "error: "
88+
<< RESET
89+
<< "type alias or nested type not found"
90+
<< "\n";
8991

9092
printCodeFrame(err, ctx);
9193

9294
std::cerr << YELLOW
93-
<< "hint: the template argument does not provide the nested type you are trying to use"
94-
<< RESET << "\n";
95+
<< "hint: "
96+
<< RESET
97+
<< "the template argument does not provide the nested type you are trying to use"
98+
<< "\n";
9599

96100
std::cerr << YELLOW
97-
<< "hint: check names like T::value_type, T::iterator, or U::type and make sure the chosen type actually defines them"
98-
<< RESET << "\n";
101+
<< "hint: "
102+
<< RESET
103+
<< "check names like T::value_type, T::iterator, or U::type and make sure the chosen type actually defines them"
104+
<< "\n";
99105

100106
std::cerr << GREEN
101-
<< "at: " << fileName << ":" << err.line << ":" << err.column
102-
<< RESET << "\n";
107+
<< "at: "
108+
<< RESET
109+
<< fileName << ":" << err.line << ":" << err.column
110+
<< "\n";
103111

104112
return true;
105113
}

src/errors/template/SubstitutionFailureRule.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,30 @@ namespace vix::cli::errors::template_rules
8787
const std::string fileName = filePath.filename().string();
8888

8989
std::cerr << RED
90-
<< "error: template substitution failed"
91-
<< RESET << "\n";
90+
<< "error: "
91+
<< RESET
92+
<< "template substitution failed"
93+
<< "\n";
9294

9395
printCodeFrame(err, ctx);
9496

9597
std::cerr << YELLOW
96-
<< "hint: the compiler tried to instantiate a template with your types, but one or more required expressions or types were not valid"
97-
<< RESET << "\n";
98+
<< "hint: "
99+
<< RESET
100+
<< "the compiler tried to instantiate a template with your types, but one or more required expressions or types were not valid"
101+
<< "\n";
98102

99103
std::cerr << YELLOW
100-
<< "hint: check the template constraints, required member types/functions, and whether the chosen type really supports the operations used inside the template"
101-
<< RESET << "\n";
104+
<< "hint: "
105+
<< RESET
106+
<< "check the template constraints, required member types/functions, and whether the chosen type really supports the operations used inside the template"
107+
<< "\n";
102108

103109
std::cerr << GREEN
104-
<< "at: " << fileName << ":" << err.line << ":" << err.column
105-
<< RESET << "\n";
110+
<< "at: "
111+
<< RESET
112+
<< fileName << ":" << err.line << ":" << err.column
113+
<< "\n";
106114

107115
return true;
108116
}

src/errors/template/TemplateArgumentMismatchRule.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,22 +87,30 @@ namespace vix::cli::errors::template_rules
8787
const std::string fileName = filePath.filename().string();
8888

8989
std::cerr << RED
90-
<< "error: template argument mismatch"
91-
<< RESET << "\n";
90+
<< "error: "
91+
<< RESET
92+
<< "template argument mismatch"
93+
<< "\n";
9294

9395
printCodeFrame(err, ctx);
9496

9597
std::cerr << YELLOW
96-
<< "hint: one or more template arguments do not match what this template expects"
97-
<< RESET << "\n";
98+
<< "hint: "
99+
<< RESET
100+
<< "one or more template arguments do not match what this template expects"
101+
<< "\n";
98102

99103
std::cerr << YELLOW
100-
<< "hint: check the number of template parameters and whether each argument should be a type, a value, or another template"
101-
<< RESET << "\n";
104+
<< "hint: "
105+
<< RESET
106+
<< "check the number of template parameters and whether each argument should be a type, a value, or another template"
107+
<< "\n";
102108

103109
std::cerr << GREEN
104-
<< "at: " << fileName << ":" << err.line << ":" << err.column
105-
<< RESET << "\n";
110+
<< "at: "
111+
<< RESET
112+
<< fileName << ":" << err.line << ":" << err.column
113+
<< "\n";
106114

107115
return true;
108116
}

0 commit comments

Comments
 (0)