Skip to content

Commit df5240f

Browse files
committed
fix
1 parent b15d7ef commit df5240f

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

be/src/common/exception.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ Exception::Exception(int code, const std::string_view& msg, bool from_status) {
4848
// std::cout << "Exception: " << code << ", " << msg << ", " << get_stack_trace(0, "DISABLED")
4949
// << std::endl;
5050
#endif
51+
52+
fmt::memory_buffer buf;
53+
fmt::format_to(buf, "[E{}] {}", _code, _err_msg ? _err_msg->_msg : "");
54+
if (_err_msg && !_err_msg->_stack.empty()) {
55+
fmt::format_to(buf, "\n{}", _err_msg->_stack);
56+
}
57+
_cache_string = fmt::to_string(buf);
58+
5159
if (config::exit_on_exception) {
5260
LOG(FATAL) << "[ExitOnException] error code: " << code << ", message: " << msg;
5361
}

be/src/common/exception.h

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ class Exception : public std::exception {
4646
int code() const { return _code; }
4747
std::string message() const { return _err_msg ? _err_msg->_msg : ""; }
4848

49-
const std::string& to_string() const;
49+
const std::string& to_string() const { return _cache_string; }
5050

51-
const char* what() const noexcept override { return to_string().c_str(); }
51+
const char* what() const noexcept override { return _cache_string.c_str(); }
5252

5353
Status to_status() const { return {code(), _err_msg->_msg, _err_msg->_stack}; }
5454

@@ -61,22 +61,8 @@ class Exception : public std::exception {
6161
std::string _stack;
6262
};
6363
std::unique_ptr<ErrMsg> _err_msg;
64-
mutable std::string _cache_string;
64+
std::string _cache_string {};
6565
};
66-
67-
inline const std::string& Exception::to_string() const {
68-
if (!_cache_string.empty()) {
69-
return _cache_string;
70-
}
71-
fmt::memory_buffer buf;
72-
fmt::format_to(buf, "[E{}] {}", _code, _err_msg ? _err_msg->_msg : "");
73-
if (_err_msg && !_err_msg->_stack.empty()) {
74-
fmt::format_to(buf, "\n{}", _err_msg->_stack);
75-
}
76-
_cache_string = fmt::to_string(buf);
77-
return _cache_string;
78-
}
79-
8066
} // namespace doris
8167

8268
#define RETURN_IF_CATCH_EXCEPTION(stmt) \

0 commit comments

Comments
 (0)