4 #include "util/status.h" 6 #include "base/logging.h" 12 const Status Status::CANCELLED(StatusCode::CANCELLED,
"Cancelled");
13 const Status Status::OK;
15 void Status::AddErrorMsg(StatusCode::Code code,
const std::string& msg) {
17 error_detail_.reset(
new ErrorDetail{code, msg});
19 error_detail_->error_msgs.push_back(msg);
24 void Status::AddErrorMsg(
const std::string& msg) { AddErrorMsg(StatusCode::INTERNAL_ERROR, msg); }
26 void Status::AddError(
const Status& status) {
29 AddErrorMsg(status.code(), status.ToString());
32 void Status::GetErrorMsgs(std::vector<string>* msgs)
const {
34 if (error_detail_ != NULL) {
35 *msgs = error_detail_->error_msgs;
39 void Status::GetErrorMsg(
string* msg)
const {
41 if (error_detail_ != NULL) {
42 if (StatusCode::Code_IsValid(error_detail_->error_code)) {
43 const string& str = StatusCode::Code_Name(error_detail_->error_code);
44 msg->append(str).append(
" ");
46 for (
const string& e : error_detail_->error_msgs) {
47 msg->append(e).append(
"\n");
49 if (!error_detail_->error_msgs.empty()) {
57 std::ostream& operator<<(std::ostream& o,
const Status& status) {
58 o << status.ToString();
64 bool StatusFailPrintImpl(
const Status& st) {
65 LOG_IF(ERROR, !st.ok()) <<
"Status error " << st;
70 void PrintFatal(
const char* file,
unsigned line_num,
const Status& st) {
71 string msg = st.ToString();
72 ::google::LogMessage{file, int(line_num), google::GLOG_FATAL}.stream() << msg;