22
22
* Errors a drizzled can give you
26
#include <drizzled/internal/my_sys.h>
27
#include <drizzled/definitions.h>
28
#include <drizzled/error.h>
29
#include <drizzled/gettext.h>
30
#include <drizzled/identifier.h>
31
#include <drizzled/util/find_ptr.h>
26
#include "drizzled/internal/my_sys.h"
27
#include "drizzled/definitions.h"
28
#include "drizzled/error.h"
29
#include "drizzled/gettext.h"
31
#include "drizzled/identifier.h"
33
33
#include <boost/unordered_map.hpp>
41
class ErrorStringNotFound: public std::exception
38
48
ErrorMap& get_error_map()
48
58
return get_error_map().mapping_;
51
void add_error_message(error_t error_code,
61
void add_error_message(drizzled::error_t error_code,
52
62
const std::string &error_name,
53
63
const std::string &message)
55
65
get_error_map().add(error_code, error_name, message);
58
const char* error_message(error_t code)
68
const char * error_message(drizzled::error_t code)
60
const std::string* ptr = get_error_map().find(code);
61
return ptr ? ptr->c_str() : get_error_map().find(ER_UNKNOWN_ERROR)->c_str();
72
return get_error_map().find(code).c_str();
74
catch (ErrorStringNotFound const& e)
76
return get_error_map().find(ER_UNKNOWN_ERROR).c_str();
64
80
error_handler_func error_handler_hook= NULL;
68
void access(const drizzled::identifier::User& user)
70
my_error(ER_ACCESS_DENIED_ERROR, MYF(0), user.getSQLPath().c_str(), ER(user.hasPassword() ? ER_YES : ER_NO));
73
void access(const drizzled::identifier::User& user, const drizzled::identifier::Schema& schema)
75
my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), user.getSQLPath().c_str(), schema.getSQLPath().c_str());
78
void access(const drizzled::identifier::User& user, const drizzled::identifier::Table& table)
80
my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), user.getSQLPath().c_str(), table.getSQLPath().c_str());
83
static error::level_t _verbosity= error::ERROR;
84
static std::string _verbosity_strint;
86
const std::string &verbose_string()
92
static std::string _arg= "INSPECT";
97
static std::string _arg= "INFO";
102
static std::string _arg= "WARN";
107
static std::string _arg= "ERROR";
115
error::level_t &verbosity()
120
void check_verbosity(const std::string &arg)
122
if (not arg.compare("INSPECT"))
124
_verbosity= error::INSPECT;
126
else if (not arg.compare("INFO"))
128
_verbosity= error::INFO;
130
else if (not arg.compare("WARN"))
132
_verbosity= error::WARN;
134
else if (not arg.compare("ERROR"))
136
_verbosity= error::ERROR;
144
84
my_error family functions have to be used according following rules:
163
103
my_error(nr, MyFlags, ref.c_str());
166
void my_error(error_t nr, const drizzled::Identifier& id, myf MyFlags)
106
void my_error(error_t nr, drizzled::Identifier::const_reference ref, myf MyFlags)
168
my_error(nr, MyFlags, id.getSQLPath().c_str());
109
ref.getSQLPath(temp);
110
my_error(nr, MyFlags, temp.c_str());
171
113
void my_error(error_t nr)
176
118
void my_error(error_t nr, myf MyFlags, ...)
179
122
char ebuff[ERRMSGSIZE + 20];
181
if (const std::string* format= get_error_map().find(nr))
126
format= get_error_map().find(nr);
183
127
va_start(args,MyFlags);
184
(void) vsnprintf (ebuff, sizeof(ebuff), _(format->c_str()), args);
128
(void) vsnprintf (ebuff, sizeof(ebuff), _(format.c_str()), args);
131
catch (ErrorStringNotFound const& e)
188
133
(void) snprintf (ebuff, sizeof(ebuff), _("Unknown error %d"), nr);
189
135
(*error_handler_hook)(nr, ebuff, MyFlags);
224
void my_message(drizzled::error_t error, const char *str, myf MyFlags)
170
void my_message(drizzled::error_t error, const char *str, register myf MyFlags)
226
172
(*error_handler_hook)(error, str, MyFlags);
233
179
const std::string &error_name,
234
180
const std::string &message)
236
if (not mapping_.count(error_num))
182
if (mapping_.find(error_num) == mapping_.end())
238
184
// Log the error.
239
185
mapping_[error_num]= ErrorMap::value_type(error_name, message);
247
const std::string* ErrorMap::find(drizzled::error_t error_num) const
193
const std::string &ErrorMap::find(drizzled::error_t error_num) const
249
const ErrorMessageMap::mapped_type* pos= find_ptr(mapping_, error_num);
250
return pos ? &pos->second : NULL;
195
ErrorMessageMap::const_iterator pos= mapping_.find(error_num);
196
if (pos == mapping_.end())
198
throw ErrorStringNotFound();
200
return pos->second.second;
253
203
#define ADD_ERROR_MESSAGE(code, msg) add(code, STRINGIFY_ARG(code), msg)
296
246
ADD_ERROR_MESSAGE(ER_OUT_OF_RESOURCES, N_("Out of memory; check if drizzled or some other process uses all available memory; if not, you may have to use 'ulimit' to allow drizzled to use more memory or you can add more swap space"));
297
247
ADD_ERROR_MESSAGE(ER_BAD_HOST_ERROR, N_("Can't get hostname for your address"));
298
248
ADD_ERROR_MESSAGE(ER_HANDSHAKE_ERROR, N_("Bad handshake"));
300
// Access error messages
301
ADD_ERROR_MESSAGE(ER_DBACCESS_DENIED_ERROR, N_("Access denied for user '%s' to schema '%s'"));
302
ADD_ERROR_MESSAGE(ER_TABLEACCESS_DENIED_ERROR, N_("Access denied for user '%s' to table '%s'"));
303
ADD_ERROR_MESSAGE(ER_ACCESS_DENIED_ERROR, N_("Access denied for user '%s' (using password: %s)"));
249
ADD_ERROR_MESSAGE(ER_DBACCESS_DENIED_ERROR, N_("Access denied for user '%-.48s'@'%-.64s' to schema '%-.192s'"));
250
ADD_ERROR_MESSAGE(ER_ACCESS_DENIED_ERROR, N_("Access denied for user '%-.48s'@'%-.64s' (using password: %s)"));
305
251
ADD_ERROR_MESSAGE(ER_NO_DB_ERROR, N_("No schema selected"));
306
252
ADD_ERROR_MESSAGE(ER_UNKNOWN_COM_ERROR, N_("Unknown command"));
307
253
ADD_ERROR_MESSAGE(ER_BAD_NULL_ERROR, N_("Column '%-.192s' cannot be null"));
384
330
ADD_ERROR_MESSAGE(ER_WRONG_VALUE_COUNT_ON_ROW, N_("Column count doesn't match value count at row %ld"));
385
331
ADD_ERROR_MESSAGE(ER_CANT_REOPEN_TABLE, N_("Can't reopen table: '%-.192s'"));
386
332
ADD_ERROR_MESSAGE(ER_MIX_OF_GROUP_FUNC_AND_FIELDS, N_("Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause"));
333
ADD_ERROR_MESSAGE(ER_NO_SUCH_TABLE, N_("Table '%-.192s.%-.192s' doesn't exist"));
387
334
ADD_ERROR_MESSAGE(ER_SYNTAX_ERROR, N_("You have an error in your SQL syntax; check the manual that corresponds to your Drizzle server version for the right syntax to use"));
388
335
ADD_ERROR_MESSAGE(ER_NET_PACKET_TOO_LARGE, N_("Got a packet bigger than 'max_allowed_packet' bytes"));
389
336
ADD_ERROR_MESSAGE(ER_NET_PACKETS_OUT_OF_ORDER, N_("Got packets out of order"));
557
504
ADD_ERROR_MESSAGE(ER_USE_SQL_BIG_RESULT, N_("Temporary table too large, rerun with SQL_BIG_RESULT."));
558
505
ADD_ERROR_MESSAGE(ER_UNKNOWN_ENGINE_OPTION, N_("Unknown table engine option key/pair %s = %s."));
559
506
ADD_ERROR_MESSAGE(ER_UNKNOWN_SCHEMA_OPTION, N_("Unknown schema engine option key/pair %s = %s."));
560
ADD_ERROR_MESSAGE(ER_CARTESIAN_JOIN_ATTEMPTED, N_("Implicit cartesian join attempted."));
561
508
ADD_ERROR_MESSAGE(ER_ADMIN_ACCESS, N_("Admin access not allowed from this username/IP address."));
563
510
// User lock/barrier error messages
609
556
ADD_ERROR_MESSAGE(ER_ASSERT_NULL, N_("Assertion '%s' failed, the result was NULL."));
611
558
// Some old error values use the same strings as some new error values.
612
ADD_ERROR_MESSAGE(EE_FILENOTFOUND, *find(ER_FILE_NOT_FOUND));
613
ADD_ERROR_MESSAGE(EE_CANTCREATEFILE, *find(ER_CANT_CREATE_FILE));
614
ADD_ERROR_MESSAGE(EE_READ, *find(ER_ERROR_ON_READ));
615
ADD_ERROR_MESSAGE(EE_WRITE, *find(ER_ERROR_ON_WRITE));
616
ADD_ERROR_MESSAGE(EE_BADCLOSE, *find(ER_ERROR_ON_CLOSE));
617
ADD_ERROR_MESSAGE(EE_OUTOFMEMORY, *find(ER_OUTOFMEMORY));
618
ADD_ERROR_MESSAGE(EE_DELETE, *find(ER_CANT_DELETE_FILE));
619
ADD_ERROR_MESSAGE(EE_LINK, *find(ER_ERROR_ON_RENAME));
620
ADD_ERROR_MESSAGE(EE_EOFERR, *find(ER_UNEXPECTED_EOF));
621
ADD_ERROR_MESSAGE(EE_CANTLOCK, *find(ER_CANT_LOCK));
622
ADD_ERROR_MESSAGE(EE_DIR, *find(ER_CANT_READ_DIR));
623
ADD_ERROR_MESSAGE(EE_STAT, *find(ER_CANT_GET_STAT));
624
ADD_ERROR_MESSAGE(EE_DISK_FULL, *find(ER_DISK_FULL));
559
ADD_ERROR_MESSAGE(EE_FILENOTFOUND, find(ER_FILE_NOT_FOUND));
560
ADD_ERROR_MESSAGE(EE_CANTCREATEFILE, find(ER_CANT_CREATE_FILE));
561
ADD_ERROR_MESSAGE(EE_READ, find(ER_ERROR_ON_READ));
562
ADD_ERROR_MESSAGE(EE_WRITE, find(ER_ERROR_ON_WRITE));
563
ADD_ERROR_MESSAGE(EE_BADCLOSE, find(ER_ERROR_ON_CLOSE));
564
ADD_ERROR_MESSAGE(EE_OUTOFMEMORY, find(ER_OUTOFMEMORY));
565
ADD_ERROR_MESSAGE(EE_DELETE, find(ER_CANT_DELETE_FILE));
566
ADD_ERROR_MESSAGE(EE_LINK, find(ER_ERROR_ON_RENAME));
567
ADD_ERROR_MESSAGE(EE_EOFERR, find(ER_UNEXPECTED_EOF));
568
ADD_ERROR_MESSAGE(EE_CANTLOCK, find(ER_CANT_LOCK));
569
ADD_ERROR_MESSAGE(EE_DIR, find(ER_CANT_READ_DIR));
570
ADD_ERROR_MESSAGE(EE_STAT, find(ER_CANT_GET_STAT));
571
ADD_ERROR_MESSAGE(EE_DISK_FULL, find(ER_DISK_FULL));
626
573
// Catalog related errors
627
574
ADD_ERROR_MESSAGE(ER_CATALOG_CANNOT_CREATE, N_("Cannot create catalog '%s'."));
633
580
ADD_ERROR_MESSAGE(ER_CATALOG_NO_LOCK, N_("Could not gain lock on '%s'."));
634
581
ADD_ERROR_MESSAGE(ER_CORRUPT_CATALOG_DEFINITION, N_("Corrupt or invalid catalog definition for '%s' : '%s'."));
635
582
ADD_ERROR_MESSAGE(ER_WRONG_NAME_FOR_CATALOG, N_("Invalid catalog name."));
636
ADD_ERROR_MESSAGE(ER_USE_DATA_DICTIONARY, N_("Engine status is now stored in the data_dictionary tables, please use these instead."));
637
ADD_ERROR_MESSAGE(ER_TRANSACTION_ALREADY_STARTED, N_("There is already a transaction in progress"));
638
ADD_ERROR_MESSAGE(ER_NO_LOCK_HELD, N_("No lock is held by this connection."));
641
587
} /* namespace drizzled */