forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatus.cpp
More file actions
98 lines (83 loc) · 2.87 KB
/
Copy pathstatus.cpp
File metadata and controls
98 lines (83 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2011 The LevelDB Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "common/status.h"
#include <gen_cpp/Status_types.h>
#include <gen_cpp/types.pb.h> // for PStatus
#include <rapidjson/encodings.h>
#include <rapidjson/prettywriter.h>
#include <rapidjson/stringbuffer.h>
#include <algorithm>
#include <new>
#include <vector>
#include "service/backend_options.h"
namespace doris {
namespace ErrorCode {
ErrorCodeState error_states[MAX_ERROR_CODE_DEFINE_NUM];
ErrorCodeInitializer error_code_init(10);
} // namespace ErrorCode
void Status::to_thrift(TStatus* s) const {
s->error_msgs.clear();
if (ok()) {
s->status_code = TStatusCode::OK;
return;
}
// Currently, there are many error codes, not defined in thrift and need pass to FE.
// DCHECK(_code > 0)
// << "The error code has to > 0 because TStatusCode need it > 0, it's actual value is "
// << _code;
s->status_code = (int16_t)_code > 0 ? (TStatusCode::type)_code : TStatusCode::INTERNAL_ERROR;
if (_code == ErrorCode::VERSION_ALREADY_MERGED) {
s->status_code = TStatusCode::OLAP_ERR_VERSION_ALREADY_MERGED;
} else if (_code == ErrorCode::TABLE_NOT_FOUND) {
s->status_code = TStatusCode::TABLET_MISSING;
}
s->error_msgs.push_back(fmt::format("({})[{}]{}", BackendOptions::get_localhost(),
code_as_string(), _err_msg ? _err_msg->_msg : ""));
s->__isset.error_msgs = true;
}
TStatus Status::to_thrift() const {
TStatus s;
to_thrift(&s);
return s;
}
void Status::to_protobuf(PStatus* s) const {
s->clear_error_msgs();
s->set_status_code((int)_code);
if (!ok()) {
s->add_error_msgs(fmt::format("({})[{}]{}", BackendOptions::get_localhost(),
code_as_string(), _err_msg ? _err_msg->_msg : ""));
}
}
Status& Status::prepend(std::string_view msg) {
if (!ok()) {
if (_err_msg == nullptr) {
_err_msg = std::make_unique<ErrMsg>();
}
_err_msg->_msg = std::string(msg) + _err_msg->_msg;
}
return *this;
}
Status& Status::append(std::string_view msg) {
if (!ok()) {
if (_err_msg == nullptr) {
_err_msg = std::make_unique<ErrMsg>();
}
_err_msg->_msg.append(msg);
}
return *this;
}
std::string Status::to_json() const {
rapidjson::StringBuffer s;
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(s);
writer.StartObject();
// status
writer.Key("status");
writer.String(code_as_string().c_str());
// msg
writer.Key("msg");
ok() ? writer.String("OK") : writer.String(_err_msg ? _err_msg->_msg.c_str() : "");
writer.EndObject();
return s.GetString();
}
} // namespace doris