Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
error-util.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_UTIL_ERROR_UTIL_H
17 #define IMPALA_UTIL_ERROR_UTIL_H
18 
19 
20 #include <string>
21 #include <vector>
22 #include <boost/cstdint.hpp>
23 #include <boost/lexical_cast.hpp>
24 
25 #include "gen-cpp/CatalogObjects_types.h"
26 #include "gen-cpp/ErrorCodes_types.h"
27 #include "gen-cpp/ErrorCodes_constants.h"
28 #include "gen-cpp/ImpalaInternalService_types.h"
29 #include "gutil/strings/substitute.h"
30 
31 namespace impala {
32 
36 std::string GetStrErrMsg();
37 
41  const std::vector<TTableName>& tables_missing_stats);
42 
43 
47 class ErrorMsg {
48  public:
49  typedef strings::internal::SubstituteArg ArgType;
50 
52  ErrorMsg() : error_(TErrorCode::OK) {}
53 
58  ErrorMsg(TErrorCode::type error);
59  ErrorMsg(TErrorCode::type error, const ArgType& arg0);
60  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1);
61  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
62  const ArgType& arg2);
63  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
64  const ArgType& arg2, const ArgType& arg3);
65  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
66  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4);
67  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
68  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
69  const ArgType& arg5);
70  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
71  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
72  const ArgType& arg5, const ArgType& arg6);
73  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
74  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
75  const ArgType& arg5, const ArgType& arg6, const ArgType& arg7);
76  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
77  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
78  const ArgType& arg5, const ArgType& arg6, const ArgType& arg7,
79  const ArgType& arg8);
80  ErrorMsg(TErrorCode::type error, const ArgType& arg0, const ArgType& arg1,
81  const ArgType& arg2, const ArgType& arg3, const ArgType& arg4,
82  const ArgType& arg5, const ArgType& arg6, const ArgType& arg7,
83  const ArgType& arg8, const ArgType& arg9);
84 
85  ErrorMsg(TErrorCode::type error, const std::vector<string>& detail)
86  : error_(error), details_(detail) {}
87 
94  static ErrorMsg Init(TErrorCode::type error, const ArgType& arg0 = ArgType::NoArg,
95  const ArgType& arg1 = ArgType::NoArg,
96  const ArgType& arg2 = ArgType::NoArg,
97  const ArgType& arg3 = ArgType::NoArg,
98  const ArgType& arg4 = ArgType::NoArg,
99  const ArgType& arg5 = ArgType::NoArg,
100  const ArgType& arg6 = ArgType::NoArg,
101  const ArgType& arg7 = ArgType::NoArg,
102  const ArgType& arg8 = ArgType::NoArg,
103  const ArgType& arg9 = ArgType::NoArg);
104 
105  TErrorCode::type error() const { return error_; }
106 
108  void AddDetail(const std::string& d) {
109  details_.push_back(d);
110  }
111 
113  void SetError(TErrorCode::type e) {
114  error_ = e;
115  }
116 
118  const std::string& msg() const {
119  return message_;
120  }
121 
122  const std::vector<std::string>& details() const {
123  return details_;
124  }
125 
128  std::string GetFullMessageDetails() const {
129  std::stringstream ss;
130  ss << message_ << "\n";
131  for(size_t i=0, end=details_.size(); i < end; ++i) {
132  ss << details_[i] << "\n";
133  }
134  return ss.str();
135  }
136 
137 private:
138  TErrorCode::type error_;
139  std::string message_;
140  std::vector<std::string> details_;
141 };
142 
144 typedef std::map<TErrorCode::type, TErrorLogEntry> ErrorLogMap;
145 
150 void MergeErrorMaps(ErrorLogMap* left, const ErrorLogMap& right);
151 
156 void AppendError(ErrorLogMap* map, const ErrorMsg& e);
157 
159 void PrintErrorMap(std::ostream* stream, const ErrorLogMap& errors);
160 
163 size_t ErrorCount(const ErrorLogMap& errors);
164 
167 std::string PrintErrorMapToString(const ErrorLogMap& errors);
168 
169 }
170 
171 #endif
const std::string & msg() const
Returns the formatted error string.
Definition: error-util.h:118
string GetTablesMissingStatsWarning(const vector< TTableName > &tables_missing_stats)
Definition: error-util.cc:40
string PrintErrorMapToString(const ErrorLogMap &errors)
Definition: error-util.cc:153
TErrorCode::type error_
Definition: error-util.h:138
TErrorCode::type error() const
Definition: error-util.h:105
void MergeErrorMaps(ErrorLogMap *left, const ErrorLogMap &right)
Definition: error-util.cc:159
ErrorMsg(TErrorCode::type error, const std::vector< string > &detail)
Definition: error-util.h:85
void AppendError(ErrorLogMap *map, const ErrorMsg &e)
Definition: error-util.cc:177
string GetStrErrMsg()
Definition: error-util.cc:30
std::vector< std::string > details_
Definition: error-util.h:140
void SetError(TErrorCode::type e)
Set a specific error code.
Definition: error-util.h:113
void AddDetail(const std::string &d)
Add detail string message.
Definition: error-util.h:108
size_t ErrorCount(const ErrorLogMap &errors)
Definition: error-util.cc:191
std::string GetFullMessageDetails() const
Definition: error-util.h:128
static ErrorMsg Init(TErrorCode::type error, const ArgType &arg0=ArgType::NoArg, const ArgType &arg1=ArgType::NoArg, const ArgType &arg2=ArgType::NoArg, const ArgType &arg3=ArgType::NoArg, const ArgType &arg4=ArgType::NoArg, const ArgType &arg5=ArgType::NoArg, const ArgType &arg6=ArgType::NoArg, const ArgType &arg7=ArgType::NoArg, const ArgType &arg8=ArgType::NoArg, const ArgType &arg9=ArgType::NoArg)
Definition: error-util.cc:122
strings::internal::SubstituteArg ArgType
Definition: error-util.h:49
void PrintErrorMap(ostream *stream, const ErrorLogMap &errors)
Definition: error-util.cc:136
std::string message_
Definition: error-util.h:139
const std::vector< std::string > & details() const
Definition: error-util.h:122
ErrorMsg()
Trivial constructor.
Definition: error-util.h:52
std::map< TErrorCode::type, TErrorLogEntry > ErrorLogMap
Tracks log messages per error code.
Definition: error-util.h:144