Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit a66a3fa

Browse files
committed
[Impeller] Validation logs indicate where in code the validation error happened.
Earlier, all validation logs originated from validation.cc which was not useful at all since you had to find the string in the source.
1 parent 04e4989 commit a66a3fa

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

impeller/base/validation.cc

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,31 +33,30 @@ ScopedValidationFatal::~ScopedValidationFatal() {
3333
sValidationLogsAreFatal--;
3434
}
3535

36-
ValidationLog::ValidationLog() = default;
36+
ValidationLog::ValidationLog(const char* file, int line)
37+
: file_(file), line_(line) {}
3738

3839
ValidationLog::~ValidationLog() {
3940
if (sValidationLogsDisabledCount <= 0) {
40-
ImpellerValidationBreak(stream_.str().c_str());
41+
ImpellerValidationBreak(stream_.str().c_str(), file_, line_);
4142
}
4243
}
4344

4445
std::ostream& ValidationLog::GetStream() {
4546
return stream_;
4647
}
4748

48-
void ImpellerValidationBreak(const char* message) {
49-
std::stringstream stream;
49+
void ImpellerValidationBreak(const char* message, const char* file, int line) {
50+
const auto severity =
51+
ImpellerValidationErrorsAreFatal() ? fml::LOG_FATAL : fml::LOG_ERROR;
52+
auto fml_log = fml::LogMessage{severity, file, line, nullptr};
53+
fml_log.stream() <<
5054
#if FLUTTER_RELEASE
51-
stream << "Impeller validation: " << message;
52-
#else
53-
stream << "Break on '" << __FUNCTION__
54-
<< "' to inspect point of failure: " << message;
55-
#endif
56-
if (sValidationLogsAreFatal > 0) {
57-
FML_LOG(FATAL) << stream.str();
58-
} else {
59-
FML_LOG(ERROR) << stream.str();
60-
}
55+
"Impeller validation: " << message;
56+
#else // FLUTTER_RELEASE
57+
"Break on '" << __FUNCTION__
58+
<< "' to inspect point of failure: " << message;
59+
#endif // FLUTTER_RELEASE
6160
}
6261

6362
bool ImpellerValidationErrorsAreFatal() {

impeller/base/validation.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,15 @@ namespace impeller {
1111

1212
class ValidationLog {
1313
public:
14-
ValidationLog();
14+
ValidationLog(const char* file, int line);
1515

1616
~ValidationLog();
1717

1818
std::ostream& GetStream();
1919

2020
private:
21+
const char* file_ = nullptr;
22+
int line_ = 0;
2123
std::ostringstream stream_;
2224

2325
ValidationLog(const ValidationLog&) = delete;
@@ -29,7 +31,7 @@ class ValidationLog {
2931
ValidationLog& operator=(ValidationLog&&) = delete;
3032
};
3133

32-
void ImpellerValidationBreak(const char* message);
34+
void ImpellerValidationBreak(const char* message, const char* file, int line);
3335

3436
void ImpellerValidationErrorsSetFatal(bool fatal);
3537

@@ -70,6 +72,6 @@ struct ScopedValidationFatal {
7072
/// are fatal. The runtime-mode restriction still applies. This usually
7173
/// happens in test environments.
7274
///
73-
#define VALIDATION_LOG ::impeller::ValidationLog{}.GetStream()
75+
#define VALIDATION_LOG ::impeller::ValidationLog{__FILE__, __LINE__}.GetStream()
7476

7577
#endif // FLUTTER_IMPELLER_BASE_VALIDATION_H_

0 commit comments

Comments
 (0)