0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Error.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 3
9  * of the License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
29 #include <Common/Compat.h>
30 #include "Error.h"
31 
32 #include <Common/Logger.h>
33 
34 #include <iomanip>
35 #include <unordered_map>
36 
37 using namespace Hypertable;
38 
39 namespace {
40  struct ErrorInfo {
41  int code;
42  const char *text;
43  };
44 
45  ErrorInfo error_info[] = {
46  { Error::UNPOSSIBLE, "But that's unpossible!" },
47  { Error::EXTERNAL, "External error" },
48  { Error::FAILED_EXPECTATION, "HYPERTABLE failed expectation" },
49  { Error::OK, "HYPERTABLE ok" },
50  { Error::PROTOCOL_ERROR, "HYPERTABLE protocol error" },
51  { Error::REQUEST_TRUNCATED, "HYPERTABLE request truncated" },
52  { Error::RESPONSE_TRUNCATED, "HYPERTABLE response truncated" },
53  { Error::REQUEST_TIMEOUT, "HYPERTABLE request timeout" },
54  { Error::LOCAL_IO_ERROR, "HYPERTABLE local i/o error" },
55  { Error::BAD_ROOT_LOCATION, "HYPERTABLE bad root location" },
56  { Error::BAD_SCHEMA, "HYPERTABLE bad schema" },
57  { Error::INVALID_METADATA, "HYPERTABLE invalid metadata" },
58  { Error::BAD_KEY, "HYPERTABLE bad key" },
59  { Error::METADATA_NOT_FOUND, "HYPERTABLE metadata not found" },
60  { Error::HQL_PARSE_ERROR, "HYPERTABLE HQL parse error" },
61  { Error::FILE_NOT_FOUND, "HYPERTABLE file not found" },
63  "HYPERTABLE block compressor unsupported type" },
65  "HYPERTABLE block compressor invalid arg" },
67  "HYPERTABLE block compressor block truncated" },
69  "HYPERTABLE block compressor bad block header" },
71  "HYPERTABLE block compressor bad magic string" },
73  "HYPERTABLE block compressor block checksum mismatch" },
75  "HYPERTABLE block compressor deflate error" },
77  "HYPERTABLE block compressor inflate error" },
79  "HYPERTABLE block compressor initialization error" },
80  { Error::TABLE_NOT_FOUND, "HYPERTABLE table does not exist" },
81  { Error::COMMAND_PARSE_ERROR, "HYPERTABLE command parse error" },
82  { Error::CONNECT_ERROR_MASTER, "HYPERTABLE Master connect error" },
84  "HYPERTABLE Hyperspace client connect error" },
85  { Error::TOO_MANY_COLUMNS, "HYPERTABLE too many columns" },
86  { Error::BAD_DOMAIN_NAME, "HYPERTABLE bad domain name" },
87  { Error::MALFORMED_REQUEST, "HYPERTABLE malformed request" },
88  { Error::BAD_MEMORY_ALLOCATION, "HYPERTABLE bad memory allocation"},
89  { Error::BAD_SCAN_SPEC, "HYPERTABLE bad scan specification"},
90  { Error::NOT_IMPLEMENTED, "HYPERTABLE not implemented"},
91  { Error::VERSION_MISMATCH, "HYPERTABLE version mismatch"},
92  { Error::CANCELLED, "HYPERTABLE cancelled"},
93  { Error::SCHEMA_PARSE_ERROR, "HYPERTABLE schema parse error" },
94  { Error::SYNTAX_ERROR, "HYPERTABLE syntax error" },
95  { Error::DOUBLE_UNGET, "HYPERTABLE double unget" },
96  { Error::EMPTY_BLOOMFILTER, "HYPERTABLE empty bloom filter" },
97  { Error::BLOOMFILTER_CHECKSUM_MISMATCH, "HYPERTABLE bloom filter checksum mismatch" },
98  { Error::NAME_ALREADY_IN_USE, "HYPERTABLE name already in use" },
99  { Error::NAMESPACE_DOES_NOT_EXIST, "HYPERTABLE namespace does not exist" },
100  { Error::BAD_NAMESPACE, "HYPERTABLE bad namespace" },
101  { Error::NAMESPACE_EXISTS, "HYPERTABLE namespace exists" },
102  { Error::NO_RESPONSE, "HYPERTABLE no response" },
103  { Error::NOT_ALLOWED, "HYPERTABLE not allowed" },
104  { Error::INDUCED_FAILURE, "HYPERTABLE induced failure" },
105  { Error::SERVER_SHUTTING_DOWN, "HYPERTABLE server shutting down" },
106  { Error::LOCATION_UNASSIGNED, "HYPERTABLE location unassigned" },
107  { Error::ALREADY_EXISTS, "HYPERTABLE cell already exists" },
108  { Error::CHECKSUM_MISMATCH, "HYPERTABLE checksum mismatch" },
109  { Error::CLOSED, "HYPERTABLE closed" },
110  { Error::RANGESERVER_NOT_FOUND, "HYPERTABLE RangeServer not found" },
111  { Error::CONNECTION_NOT_INITIALIZED, "HYPERTABLE connection not initialized" },
112  { Error::DUPLICATE_RANGE, "HYPERTABLE duplicate range" },
113  { Error::INVALID_PSEUDO_TABLE_NAME, "HYPERTABLE invalid pseudo-table name" },
114  { Error::BAD_FORMAT, "HYPERTABLE bad format" },
115  { Error::INVALID_ARGUMENT, "HYPERTABLE invalid argument" },
116  { Error::INVALID_OPERATION, "HYPERTABLE invalid operation" },
117  { Error::UNSUPPORTED_OPERATION, "HYPERTABLE unsupported operation" },
118  { Error::COLUMN_FAMILY_NOT_FOUND, "HYPERTABLE column family not found" },
119  { Error::NOTHING_TO_DO, "HYPERTABLE nothing to do" },
120  { Error::INCOMPATIBLE_OPTIONS, "HYPERTABLE incompatible options" },
121  { Error::BAD_VALUE, "HYPERTABLE bad value" },
122  { Error::SCHEMA_GENERATION_MISMATCH, "HYPERTABLE schema generation mismatch" },
123  { Error::INVALID_METHOD_IDENTIFIER, "HYPERTABLE invalid method identifier" },
124  { Error::SERVER_NOT_READY, "HYPERTABLE server not ready" },
125  { Error::CONFIG_BAD_ARGUMENT, "CONFIG bad argument(s)"},
126  { Error::CONFIG_BAD_CFG_FILE, "CONFIG bad cfg file"},
127  { Error::CONFIG_GET_ERROR, "CONFIG failed to get config value"},
128  { Error::CONFIG_BAD_VALUE, "CONFIG bad config value"},
129  { Error::COMM_NOT_CONNECTED, "COMM not connected" },
130  { Error::COMM_BROKEN_CONNECTION, "COMM broken connection" },
131  { Error::COMM_CONNECT_ERROR, "COMM connect error" },
132  { Error::COMM_ALREADY_CONNECTED, "COMM already connected" },
133  { Error::COMM_SEND_ERROR, "COMM send error" },
134  { Error::COMM_RECEIVE_ERROR, "COMM receive error" },
135  { Error::COMM_POLL_ERROR, "COMM poll error" },
136  { Error::COMM_CONFLICTING_ADDRESS, "COMM conflicting address" },
137  { Error::COMM_SOCKET_ERROR, "COMM socket error" },
138  { Error::COMM_BIND_ERROR, "COMM bind error" },
139  { Error::COMM_LISTEN_ERROR, "COMM listen error" },
140  { Error::COMM_HEADER_CHECKSUM_MISMATCH, "COMM header checksum mismatch" },
141  { Error::COMM_PAYLOAD_CHECKSUM_MISMATCH, "COMM payload checksum mismatch" },
142  { Error::COMM_BAD_HEADER, "COMM bad header" },
143  { Error::COMM_INVALID_PROXY, "COMM invalid proxy" },
144  { Error::FSBROKER_BAD_FILE_HANDLE, "FS BROKER bad file handle" },
145  { Error::FSBROKER_IO_ERROR, "FS BROKER i/o error" },
146  { Error::FSBROKER_FILE_NOT_FOUND, "FS BROKER file not found" },
147  { Error::FSBROKER_BAD_FILENAME, "FS BROKER bad filename" },
148  { Error::FSBROKER_PERMISSION_DENIED, "FS BROKER permission denied" },
149  { Error::FSBROKER_INVALID_ARGUMENT, "FS BROKER invalid argument" },
150  { Error::FSBROKER_INVALID_CONFIG, "FS BROKER invalid config value" },
151  { Error::FSBROKER_EOF, "FS BROKER end of file" },
152  { Error::HYPERSPACE_IO_ERROR, "HYPERSPACE i/o error" },
153  { Error::HYPERSPACE_CREATE_FAILED, "HYPERSPACE create failed" },
154  { Error::HYPERSPACE_FILE_NOT_FOUND, "HYPERSPACE file not found" },
155  { Error::HYPERSPACE_ATTR_NOT_FOUND, "HYPERSPACE attribute not found" },
156  { Error::HYPERSPACE_DELETE_ERROR, "HYPERSPACE delete error" },
157  { Error::HYPERSPACE_BAD_PATHNAME, "HYPERSPACE bad pathname" },
158  { Error::HYPERSPACE_PERMISSION_DENIED,"HYPERSPACE permission denied" },
159  { Error::HYPERSPACE_EXPIRED_SESSION, "HYPERSPACE expired session" },
160  { Error::HYPERSPACE_FILE_EXISTS, "HYPERSPACE file exists" },
161  { Error::HYPERSPACE_IS_DIRECTORY, "HYPERSPACE is directory" },
162  { Error::HYPERSPACE_INVALID_HANDLE, "HYPERSPACE invalid handle" },
163  { Error::HYPERSPACE_REQUEST_CANCELLED,"HYPERSPACE request cancelled" },
164  { Error::HYPERSPACE_MODE_RESTRICTION, "HYPERSPACE mode restriction" },
165  { Error::HYPERSPACE_ALREADY_LOCKED, "HYPERSPACE already locked" },
166  { Error::HYPERSPACE_LOCK_CONFLICT, "HYPERSPACE lock conflict" },
167  { Error::HYPERSPACE_NOT_LOCKED, "HYPERSPACE not locked" },
168  { Error::HYPERSPACE_BAD_ATTRIBUTE, "HYPERSPACE bad attribute" },
169  { Error::HYPERSPACE_BERKELEYDB_ERROR, "HYPERSPACE Berkeley DB error" },
170  { Error::HYPERSPACE_DIR_NOT_EMPTY, "HYPERSPACE directory not empty" },
172  "HYPERSPACE Berkeley DB deadlock" },
174  "HYPERSPACE Berkeley DB replication handle dead" },
175  { Error::HYPERSPACE_FILE_OPEN, "HYPERSPACE file open" },
176  { Error::HYPERSPACE_CLI_PARSE_ERROR, "HYPERSPACE CLI parse error" },
178  "HYPERSPACE unable to create session " },
180  "HYPERSPACE not master location" },
181 
183  "HYPERSPACE State DB error" },
185  "HYPERSPACE State DB deadlock" },
187  "HYPERSPACE State DB bad key" },
189  "HYPERSPACE State DB bad value" },
191  "HYPERSPACE State DB attempt to access/delete previously deleted state" },
193  "HYPERSPACE State DB event exists" },
195  "HYPERSPACE State DB event does not exist" },
197  "HYPERSPACE State DB event attr not found" },
199  "HYPERSPACE State DB session exists" },
201  "HYPERSPACE State DB session does not exist" },
203  "HYPERSPACE State DB session attr not found" },
205  "HYPERSPACE State DB handle exists" },
207  "HYPERSPACE State DB handle does not exist" },
209  "HYPERSPACE State DB handle attr not found" },
211  "HYPERSPACE State DB node exists" },
213  "HYPERSPACE State DB node does not exist" },
215  "HYPERSPACE State DB node attr not found" },
217  "HYPERSPACE client/server protocol version mismatch" },
218 
219  { Error::MASTER_TABLE_EXISTS, "MASTER table exists" },
220  { Error::MASTER_BAD_SCHEMA, "MASTER bad schema" },
221  { Error::MASTER_NOT_RUNNING, "MASTER not running" },
222  { Error::MASTER_NO_RANGESERVERS, "MASTER no range servers" },
223  { Error::MASTER_FILE_NOT_LOCKED, "MASTER file not locked" },
225  "MASTER range server with same location already registered" },
226  { Error::MASTER_BAD_COLUMN_FAMILY, "MASTER bad column family" },
228  "Master schema generation mismatch" },
230  "MASTER location already assigned" },
231  { Error::MASTER_LOCATION_INVALID, "MASTER location invalid" },
232  { Error::MASTER_OPERATION_IN_PROGRESS, "MASTER operation in progress" },
233  { Error::MASTER_RANGESERVER_IN_RECOVERY, "MASTER RangeServer in recovery" },
234  { Error::MASTER_BALANCE_PREVENTED, "MASTER balance operation prevented" },
235 
237  "RANGE SERVER generation mismatch" },
239  "RANGE SERVER range already loaded" },
240  { Error::RANGESERVER_RANGE_MISMATCH, "RANGE SERVER range mismatch" },
242  "RANGE SERVER non-existent range" },
243  { Error::RANGESERVER_OUT_OF_RANGE, "RANGE SERVER out of range" },
244  { Error::RANGESERVER_RANGE_NOT_FOUND, "RANGE SERVER range not found" },
246  "RANGE SERVER invalid scanner id" },
248  "RANGE SERVER schema parse error" },
250  "RANGE SERVER invalid column family id" },
252  "RANGE SERVER invalid column family" },
254  "RANGE SERVER truncated commit log" },
256  "RANGE SERVER no metadata for range" },
257  { Error::RANGESERVER_SHUTTING_DOWN, "RANGE SERVER shutting down" },
259  "RANGE SERVER corrupt commit log" },
260  { Error::RANGESERVER_UNAVAILABLE, "RANGE SERVER unavailable" },
262  "RANGE SERVER supplied revision is not strictly increasing" },
263  { Error::RANGESERVER_ROW_OVERFLOW, "RANGE SERVER row overflow" },
264  { Error::RANGESERVER_TABLE_NOT_FOUND, "RANGE SERVER table not found" },
266  "RANGE SERVER bad scan specification" },
268  "RANGE SERVER clock skew detected" },
270  "RANGE SERVER bad CellStore filename" },
272  "RANGE SERVER corrupt CellStore" },
273  { Error::RANGESERVER_TABLE_DROPPED, "RANGE SERVER table dropped" },
274  { Error::RANGESERVER_UNEXPECTED_TABLE_ID, "RANGE SERVER unexpected table ID" },
275  { Error::RANGESERVER_RANGE_BUSY, "RANGE SERVER range busy" },
276  { Error::RANGESERVER_BAD_CELL_INTERVAL, "RANGE SERVER bad cell interval" },
277  { Error::RANGESERVER_SHORT_CELLSTORE_READ, "RANGE SERVER short cellstore read" },
278  { Error::RANGESERVER_RANGE_NOT_ACTIVE, "RANGE SERVER range no longer active" },
280  "RANGE SERVER fragment already processed"},
282  "RANGE SERVER recovery plan generation mismatch"},
284  "RANGE SERVER phantom range map not found"},
286  "RANGE SERVER ranges already live"},
288  "RANGE SERVER range not yet acknowledged"},
290  "RANGE SERVER server in readonly mode"},
292  "RANGE SERVER range not yet relinquished"},
293  { Error::HQL_BAD_LOAD_FILE_FORMAT, "HQL bad load file format" },
294  { Error::HQL_BAD_COMMAND, "HQL bad command" },
295  { Error::METALOG_VERSION_MISMATCH, "METALOG version mismatch" },
296  { Error::METALOG_BAD_RS_HEADER, "METALOG bad range server metalog header" },
297  { Error::METALOG_BAD_HEADER, "METALOG bad metalog header" },
298  { Error::METALOG_ENTRY_TRUNCATED, "METALOG entry truncated" },
299  { Error::METALOG_CHECKSUM_MISMATCH, "METALOG checksum mismatch" },
300  { Error::METALOG_ENTRY_BAD_TYPE, "METALOG bad entry type" },
301  { Error::METALOG_ENTRY_BAD_ORDER, "METALOG entry out of order" },
302  { Error::METALOG_MISSING_RECOVER_ENTITY, "METALOG missing RECOVER entity" },
303  { Error::METALOG_BACKUP_FILE_MISMATCH, "METALOG backup file mismatch" },
304  { Error::METALOG_READ_ERROR, "METALOG read error" },
306  "SERIALIZATION input buffer overrun" },
307  { Error::SERIALIZATION_BAD_VINT, "SERIALIZATION bad vint encoding" },
308  { Error::SERIALIZATION_BAD_VSTR, "SERIALIZATION bad vstr encoding" },
309  { Error::SERIALIZATION_VERSION_MISMATCH, "SERIALIZATION version mismatch" },
310  { Error::THRIFTBROKER_BAD_SCANNER_ID, "THRIFT BROKER bad scanner id" },
311  { Error::THRIFTBROKER_BAD_MUTATOR_ID, "THRIFT BROKER bad mutator id" },
312  { Error::THRIFTBROKER_BAD_NAMESPACE_ID, "THRIFT BROKER bad namespace id" },
313  { Error::THRIFTBROKER_BAD_FUTURE_ID, "THRIFT BROKER bad future id" },
314  { 0, 0 }
315  };
316 
317  typedef std::unordered_map<int, const char *> TextMap;
318 
319  TextMap &build_text_map() {
320  TextMap *map = new TextMap();
321  for (int i=0; error_info[i].text != 0; i++)
322  (*map)[error_info[i].code] = error_info[i].text;
323  return *map;
324  }
325 
326  TextMap &text_map = build_text_map();
327 
328 } // local namespace
329 
330 const char *Error::get_text(int error) {
331  const char *text = text_map[error];
332  if (text == 0)
333  return "ERROR NOT REGISTERED";
334  return text;
335 }
336 
338  out << "<table border=\"1\" cellpadding=\"4\" cellspacing=\"1\" style=\"width: 720px; \">\n";
339  out << "<thead><tr><th scope=\"col\">Code<br />(hexidecimal)</th>\n";
340  out << "<th scope=\"col\">Code<br />(decimal)</th>\n";
341  out << "<th scope=\"col\">Description</th></tr></thead><tbody>\n";
342 
343  for (size_t i=0; error_info[i].text; i++) {
344  if (error_info[i].code >= 0)
345  out << "<tr><td style=\"text-align: right; \"><code>0x" << std::hex << error_info[i].code << "</code></td>\n";
346  else
347  out << "<tr><td style=\"text-align: right; \"><code></code></td>\n";
348  out << "<td style=\"text-align: right; \"><code>" << std::dec << error_info[i].code << "</code></td>\n";
349  out << "<td>" << error_info[i].text << "</td></tr>\n";
350  }
351  out << "</tbody></table>\n" << std::flush;
352 }
353 
354 namespace Hypertable {
355 
356  const char *relative_fname(const Exception &e) {
357  if (e.file()) {
358  const char *ptr = strstr(e.file(), "src/cc/");
359  return ptr ? ptr : e.file();
360  }
361  return "";
362  }
363 
364 std::ostream &operator<<(std::ostream &out, const Exception &e) {
365  out <<"Hypertable::Exception: "<< e.message() <<" - "
366  << Error::get_text(e.code());
367 
368  if (e.line()) {
369  out <<"\n\tat "<< e.func() <<" (";
370  if (Logger::get()->show_line_numbers())
371  out << e.file() <<':'<< e.line();
372  else
373  out << relative_fname(e);
374  out <<')';
375  }
376 
377  int prev_code = e.code();
378 
379  for (Exception *prev = e.prev; prev; prev = prev->prev) {
380  out <<"\n\tat "<< (prev->func() ? prev->func() : "-") <<" (";
382  out << (prev->file() ? prev->file() : "-") <<':'<< prev->line();
383  else
384  out << relative_fname(*prev);
385  out <<"): " << prev->message();
386 
387  if (prev->code() != prev_code) {
388  out <<" - "<< Error::get_text(prev->code());
389  prev_code = prev->code();
390  }
391  }
392  return out;
393 }
394 
395 std::ostream &
396 Exception::render_messages(std::ostream &out, const char *sep) const {
397  out << message() <<" - "<< Error::get_text(m_error);
398 
399  for (Exception *p = prev; p; p = p->prev)
400  out << sep << p->message();
401 
402  return out;
403 }
404 
405 } // namespace Hypertable
const char * func() const
Returns the name of the function which threw the Exception.
Definition: Error.h:403
virtual std::ostream & render_messages(std::ostream &out, const char *sep) const
Renders multiple Exceptions to an ostream.
Definition: Error.cc:396
void generate_html_error_code_documentation(std::ostream &out)
Generates and print the error documentation as html.
Definition: Error.cc:337
const char * get_text(int error)
Returns a descriptive error message.
Definition: Error.cc:330
ExceptionMessageRenderer message() const
Retrieves a Renderer for this Exception.
Definition: Error.h:429
Logging routines and macros.
Compatibility Macros for C/C++.
int m_error
The error code.
Definition: Error.h:319
std::ostream & operator<<(std::ostream &os, const crontab_entry &entry)
Helper function to write crontab_entry to an ostream.
Definition: Crontab.cc:301
const char * file() const
Returns the source code line number where the exception was thrown.
Definition: Error.h:409
Hypertable definitions
Exception * prev
The previous exception in the exception chain.
Definition: Error.h:439
const char * relative_fname(const Exception &e)
Definition: Error.cc:356
LogWriter * get()
Accessor for the LogWriter singleton instance.
Definition: Logger.cc:49
This is a generic exception class for Hypertable.
Definition: Error.h:314
bool show_line_numbers() const
Returns true if line numbers are printed.
Definition: Logger.h:108
Error codes, Exception handling, error logging.
int line() const
Returns the source code line number where the exception was thrown.
Definition: Error.h:397
int code() const
Returns the error code.
Definition: Error.h:391