~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/error.cc

  • Committer: Olaf van der Spek
  • Date: 2011-03-06 15:49:49 UTC
  • mto: (2226.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2227.
  • Revision ID: olafvdspek@gmail.com-20110306154949-zzso0l15mbwi60xb
Provide drizzle/drizzle.h

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 * Errors a drizzled can give you
23
23
 */
24
24
 
25
 
#include "config.h"
26
 
#include "drizzled/internal/my_sys.h"
27
 
#include "drizzled/definitions.h"
28
 
#include "drizzled/error.h"
29
 
#include "drizzled/gettext.h"
 
25
#include <config.h>
 
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>
30
32
 
31
33
#include <boost/unordered_map.hpp>
32
34
#include <exception>
56
58
  return get_error_map().mapping_;
57
59
}
58
60
 
59
 
void add_error_message(uint32_t error_code,
 
61
void add_error_message(drizzled::error_t error_code,
60
62
                       const std::string &error_name,
61
63
                       const std::string &message)
62
64
{
63
65
  get_error_map().add(error_code, error_name, message);
64
66
}
65
67
 
66
 
const char * error_message(unsigned int code)
 
68
const char * error_message(drizzled::error_t code)
67
69
{
68
70
  try
69
71
  {
77
79
 
78
80
error_handler_func error_handler_hook= NULL;
79
81
 
 
82
namespace error {
 
83
 
 
84
void access(drizzled::identifier::User::const_reference user)
 
85
{
 
86
  std::string user_string;
 
87
  user.getSQLPath(user_string);
 
88
 
 
89
  my_error(ER_ACCESS_DENIED_ERROR, MYF(0), user_string.c_str(),
 
90
           user.hasPassword() ? ER(ER_YES) : ER(ER_NO));
 
91
 
92
 
 
93
void access(drizzled::identifier::User::const_reference user, drizzled::identifier::Schema::const_reference schema)
 
94
{
 
95
  std::string user_string;
 
96
  user.getSQLPath(user_string);
 
97
 
 
98
  std::string schema_string;
 
99
  schema.getSQLPath(schema_string);
 
100
 
 
101
  my_error(ER_DBACCESS_DENIED_ERROR, MYF(0), user_string.c_str(), schema_string.c_str());
 
102
 
103
 
 
104
void access(drizzled::identifier::User::const_reference user, drizzled::identifier::Table::const_reference table)
 
105
{
 
106
  std::string user_string;
 
107
  user.getSQLPath(user_string);
 
108
 
 
109
  std::string table_string;
 
110
  table.getSQLPath(table_string);
 
111
 
 
112
  my_error(ER_TABLEACCESS_DENIED_ERROR, MYF(0), user_string.c_str(), table_string.c_str());
 
113
 
114
 
 
115
static error::level_t _verbosity= error::ERROR;
 
116
static std::string _verbosity_strint;
 
117
 
 
118
const std::string &verbose_string()
 
119
{
 
120
  switch (_verbosity)
 
121
  {
 
122
  case error::INSPECT:
 
123
    {
 
124
      static std::string _arg= "INSPECT";
 
125
      return _arg;
 
126
    }
 
127
  case error::INFO:
 
128
    {
 
129
      static std::string _arg= "INFO";
 
130
      return _arg;
 
131
    }
 
132
  case error::WARN:
 
133
    {
 
134
      static std::string _arg= "WARN";
 
135
      return _arg;
 
136
    }
 
137
  case error::ERROR:
 
138
    {
 
139
      static std::string _arg= "ERROR";
 
140
      return _arg;
 
141
    }
 
142
  }
 
143
 
 
144
  abort();
 
145
}
 
146
 
 
147
error::level_t &verbosity()
 
148
{
 
149
  return _verbosity;
 
150
}
 
151
 
 
152
void check_verbosity(const std::string &arg)
 
153
{
 
154
  if (not arg.compare("INSPECT"))
 
155
  {
 
156
    _verbosity= error::INSPECT;
 
157
  }
 
158
  else if (not arg.compare("INFO"))
 
159
  {
 
160
    _verbosity= error::INFO;
 
161
  }
 
162
  else if (not arg.compare("WARN"))
 
163
  {
 
164
    _verbosity= error::WARN;
 
165
  }
 
166
  else if (not arg.compare("ERROR"))
 
167
  {
 
168
    _verbosity= error::ERROR;
 
169
  }
 
170
}
 
171
 
 
172
} // namespace error
 
173
 
80
174
/*
81
175
  WARNING!
82
176
  my_error family functions have to be used according following rules:
96
190
       ...      variable list
97
191
*/
98
192
 
99
 
void my_error(int nr, myf MyFlags, ...)
 
193
void my_error(const std::string &ref, error_t nr, myf MyFlags)
 
194
{
 
195
  my_error(nr, MyFlags, ref.c_str());
 
196
 
197
 
 
198
void my_error(error_t nr, drizzled::Identifier::const_reference ref, myf MyFlags)
 
199
{
 
200
  std::string temp;
 
201
  ref.getSQLPath(temp);
 
202
  my_error(nr, MyFlags, temp.c_str());
 
203
 
204
 
 
205
void my_error(error_t nr)
 
206
{
 
207
  my_error(nr, MYF(0));
 
208
}
 
209
 
 
210
void my_error(error_t nr, myf MyFlags, ...)
100
211
{
101
212
  std::string format;
102
213
  va_list args;
127
238
      ...       variable list
128
239
*/
129
240
 
130
 
void my_printf_error(uint32_t error, const char *format, myf MyFlags, ...)
 
241
void my_printf_error(drizzled::error_t error, const char *format, myf MyFlags, ...)
131
242
{
132
243
  va_list args;
133
244
  char ebuff[ERRMSGSIZE+20];
136
247
  (void) vsnprintf (ebuff, sizeof(ebuff), format, args);
137
248
  va_end(args);
138
249
  (*error_handler_hook)(error, ebuff, MyFlags);
139
 
  return;
140
250
}
141
251
 
142
252
/*
149
259
      MyFlags   Flags
150
260
*/
151
261
 
152
 
void my_message(uint32_t error, const char *str, register myf MyFlags)
 
262
void my_message(drizzled::error_t error, const char *str, myf MyFlags)
153
263
{
154
264
  (*error_handler_hook)(error, str, MyFlags);
155
265
}
157
267
 
158
268
// Insert the message for the error.  If the error already has an existing
159
269
// mapping, an error is logged, but the function continues.
160
 
void ErrorMap::add(uint32_t error_num,
 
270
void ErrorMap::add(drizzled::error_t error_num,
161
271
                   const std::string &error_name,
162
272
                   const std::string &message)
163
273
{
164
 
  if (mapping_.find(error_num) == mapping_.end())
 
274
  if (not mapping_.count(error_num))
165
275
  {
166
276
    // Log the error.
167
277
    mapping_[error_num]= ErrorMap::value_type(error_name, message);
172
282
  }
173
283
}
174
284
 
175
 
const std::string &ErrorMap::find(uint32_t error_num) const
 
285
const std::string &ErrorMap::find(drizzled::error_t error_num) const
176
286
{
177
 
  ErrorMessageMap::const_iterator pos= mapping_.find(error_num);
178
 
  if (pos == mapping_.end())
 
287
  const ErrorMessageMap::mapped_type* pos= find_ptr(mapping_, error_num);
 
288
  if (!pos)
179
289
  {
180
290
    throw ErrorStringNotFound();
181
291
  }
182
 
  return pos->second.second;
 
292
  return pos->second;
183
293
}
184
294
 
185
295
#define ADD_ERROR_MESSAGE(code, msg) add(code, STRINGIFY_ARG(code), msg)
186
296
// Constructor sets the default mappings.
187
297
ErrorMap::ErrorMap()
188
298
{
 
299
  ADD_ERROR_MESSAGE(EE_OK, N_("SUCCESS"));
 
300
  ADD_ERROR_MESSAGE(EE_ERROR_FIRST, N_("Error on first"));
189
301
  ADD_ERROR_MESSAGE(ER_NO, N_("NO"));
190
302
  ADD_ERROR_MESSAGE(ER_YES, N_("YES"));
191
303
  ADD_ERROR_MESSAGE(ER_CANT_CREATE_FILE, N_("Can't create file '%-.200s' (errno: %d)"));
226
338
  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"));
227
339
  ADD_ERROR_MESSAGE(ER_BAD_HOST_ERROR, N_("Can't get hostname for your address"));
228
340
  ADD_ERROR_MESSAGE(ER_HANDSHAKE_ERROR, N_("Bad handshake"));
229
 
  ADD_ERROR_MESSAGE(ER_DBACCESS_DENIED_ERROR, N_("Access denied for user '%-.48s'@'%-.64s' to schema '%-.192s'"));
230
 
  ADD_ERROR_MESSAGE(ER_ACCESS_DENIED_ERROR, N_("Access denied for user '%-.48s'@'%-.64s' (using password: %s)"));
 
341
 
 
342
  // Access error messages
 
343
  ADD_ERROR_MESSAGE(ER_DBACCESS_DENIED_ERROR, N_("Access denied for user '%s' to schema '%s'"));
 
344
  ADD_ERROR_MESSAGE(ER_TABLEACCESS_DENIED_ERROR, N_("Access denied for user '%s' to table '%s'"));
 
345
  ADD_ERROR_MESSAGE(ER_ACCESS_DENIED_ERROR, N_("Access denied for user '%s' (using password: %s)"));
 
346
 
231
347
  ADD_ERROR_MESSAGE(ER_NO_DB_ERROR, N_("No schema selected"));
232
348
  ADD_ERROR_MESSAGE(ER_UNKNOWN_COM_ERROR, N_("Unknown command"));
233
349
  ADD_ERROR_MESSAGE(ER_BAD_NULL_ERROR, N_("Column '%-.192s' cannot be null"));
247
363
  ADD_ERROR_MESSAGE(ER_DUP_ENTRY, N_("Duplicate entry '%-.192s' for key %d"));
248
364
  ADD_ERROR_MESSAGE(ER_WRONG_FIELD_SPEC, N_("Incorrect column specifier for column '%-.192s'"));
249
365
  ADD_ERROR_MESSAGE(ER_PARSE_ERROR, N_("%s near '%-.80s' at line %d"));
 
366
  ADD_ERROR_MESSAGE(ER_PARSE_ERROR_UNKNOWN, N_("Parsing error near '%s'"));
250
367
  ADD_ERROR_MESSAGE(ER_EMPTY_QUERY, N_("Query was empty"));
251
368
  ADD_ERROR_MESSAGE(ER_NONUNIQ_TABLE, N_("Not unique table/alias: '%-.192s'"));
252
369
  ADD_ERROR_MESSAGE(ER_INVALID_DEFAULT, N_("Invalid default value for '%-.192s'"));
302
419
  ADD_ERROR_MESSAGE(ER_NULL_COLUMN_IN_INDEX, N_("Table handler doesn't support NULL in given index. Please change column '%-.192s' to be NOT NULL or use another handler"));
303
420
  ADD_ERROR_MESSAGE(ER_PLUGIN_NO_PATHS, N_("No paths allowed for plugin library"));
304
421
  ADD_ERROR_MESSAGE(ER_PLUGIN_EXISTS, N_("Plugin '%-.192s' already exists"));
305
 
  ADD_ERROR_MESSAGE(ER_CANT_OPEN_LIBRARY, N_("Can't open shared library '%-.192s' (errno: %d %-.128s)"));
306
 
  ADD_ERROR_MESSAGE(ER_CANT_FIND_DL_ENTRY, N_("Can't find symbol '%-.128s' in library '%-.128s'"));
 
422
  ADD_ERROR_MESSAGE(ER_CANT_OPEN_LIBRARY, N_("Can't open shared library '%-.192s' (errno: %d %s)"));
 
423
  ADD_ERROR_MESSAGE(ER_CANT_FIND_DL_ENTRY, N_("Can't find symbol '%-.128s' in library '%s'"));
307
424
  ADD_ERROR_MESSAGE(ER_UPDATE_INFO, N_("Rows matched: %ld  Changed: %ld  Warnings: %ld"));
308
425
  ADD_ERROR_MESSAGE(ER_CANT_CREATE_THREAD, N_("Can't create a new thread (errno %d); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug"));
309
426
  ADD_ERROR_MESSAGE(ER_WRONG_VALUE_COUNT_ON_ROW, N_("Column count doesn't match value count at row %ld"));
310
427
  ADD_ERROR_MESSAGE(ER_CANT_REOPEN_TABLE, N_("Can't reopen table: '%-.192s'"));
311
428
  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"));
312
 
  ADD_ERROR_MESSAGE(ER_NO_SUCH_TABLE, N_("Table '%-.192s.%-.192s' doesn't exist"));
313
429
  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"));
314
430
  ADD_ERROR_MESSAGE(ER_NET_PACKET_TOO_LARGE, N_("Got a packet bigger than 'max_allowed_packet' bytes"));
315
431
  ADD_ERROR_MESSAGE(ER_NET_PACKETS_OUT_OF_ORDER, N_("Got packets out of order"));
452
568
  ADD_ERROR_MESSAGE(ER_WRONG_PARAMETERS_TO_NATIVE_FCT, N_("Incorrect parameters in the call to native function '%-.192s'"));
453
569
  ADD_ERROR_MESSAGE(ER_DUP_ENTRY_WITH_KEY_NAME, N_("Duplicate entry '%-.64s' for key '%-.192s'"));
454
570
  ADD_ERROR_MESSAGE(ER_LOAD_DATA_INVALID_COLUMN, N_("Invalid column reference (%-.64s) in LOAD DATA"));
455
 
  ADD_ERROR_MESSAGE(ER_INVALID_UNIX_TIMESTAMP_VALUE, N_("Received an invalid value '%s' for a UNIX timestamp."));
 
571
 
456
572
  ADD_ERROR_MESSAGE(ER_INVALID_DATETIME_VALUE, N_("Received an invalid datetime value '%s'."));
 
573
  ADD_ERROR_MESSAGE(ER_INVALID_DATE_VALUE, N_("Received an invalid DATE value '%s'."));
457
574
  ADD_ERROR_MESSAGE(ER_INVALID_NULL_ARGUMENT, N_("Received a NULL argument for function '%s'."));
 
575
  ADD_ERROR_MESSAGE(ER_INVALID_TIMESTAMP_VALUE, N_("Received an invalid timestamp value '%s'."));
 
576
  ADD_ERROR_MESSAGE(ER_INVALID_TIME_VALUE, N_("Received an invalid TIME value '%s'."));
 
577
  ADD_ERROR_MESSAGE(ER_INVALID_UNIX_TIMESTAMP_VALUE, N_("Received an invalid value '%s' for a UNIX timestamp."));
 
578
 
458
579
  ADD_ERROR_MESSAGE(ER_ARGUMENT_OUT_OF_RANGE, N_("Received an out-of-range argument '%s' for function '%s'."));
459
580
  ADD_ERROR_MESSAGE(ER_INVALID_ENUM_VALUE, N_("Received an invalid enum value '%s'."));
460
581
  ADD_ERROR_MESSAGE(ER_NO_PRIMARY_KEY_ON_REPLICATED_TABLE, N_("Tables which are replicated require a primary key."));
461
 
  ADD_ERROR_MESSAGE(ER_CORRUPT_TABLE_DEFINITION, N_("Corrupt or invalid table definition: %s"));
462
 
  ADD_ERROR_MESSAGE(ER_CORRUPT_SCHEMA_DEFINITION, N_("Corrupt or invalid schema definition for %s : %s"));
 
582
 
 
583
  ADD_ERROR_MESSAGE(ER_CORRUPT_SCHEMA_DEFINITION, N_("Corrupt or invalid schema definition for '%s' : %s"));
 
584
  ADD_ERROR_MESSAGE(ER_CORRUPT_TABLE_DEFINITION, N_("Corrupt or invalid table definition for '%s': %s"));
 
585
  ADD_ERROR_MESSAGE(ER_CORRUPT_TABLE_DEFINITION_ENUM, N_("The number of enum that were required was too high for table '%s'"));
 
586
  ADD_ERROR_MESSAGE(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN, N_("Corrupt or invalid table definition for '%s'"));
 
587
  ADD_ERROR_MESSAGE(ER_CORRUPT_TABLE_DEFINITION_UNKNOWN_COLLATION, N_("Collation '%s' for table %s is invalid/unknown"));
 
588
 
 
589
  ADD_ERROR_MESSAGE(ER_TABLE_DROP, N_("Cannot drop table '%s'"));
 
590
  ADD_ERROR_MESSAGE(ER_TABLE_DROP_ERROR_OCCURRED, N_("Error occurred while dropping table '%s'"));
 
591
  ADD_ERROR_MESSAGE(ER_TABLE_PERMISSION_DENIED, N_("Permission denied to create '%s'"));
 
592
  ADD_ERROR_MESSAGE(ER_TABLE_UNKNOWN, N_("Unknown table '%s'"));
 
593
 
 
594
  ADD_ERROR_MESSAGE(ER_SCHEMA_CANNOT_CREATE, N_("Cannot create schema '%s'"));
463
595
  ADD_ERROR_MESSAGE(ER_SCHEMA_DOES_NOT_EXIST, N_("Schema does not exist: %s"));
464
596
  ADD_ERROR_MESSAGE(ER_ALTER_SCHEMA, N_("Error altering schema: %s"));
465
597
  ADD_ERROR_MESSAGE(ER_DROP_SCHEMA, +N_("Error droppping Schema : %s"));
 
598
 
466
599
  ADD_ERROR_MESSAGE(ER_USE_SQL_BIG_RESULT, N_("Temporary table too large, rerun with SQL_BIG_RESULT."));
467
600
  ADD_ERROR_MESSAGE(ER_UNKNOWN_ENGINE_OPTION, N_("Unknown table engine option key/pair %s = %s."));
468
601
  ADD_ERROR_MESSAGE(ER_UNKNOWN_SCHEMA_OPTION, N_("Unknown schema engine option key/pair %s = %s."));
469
 
 
 
602
  ADD_ERROR_MESSAGE(ER_CARTESIAN_JOIN_ATTEMPTED, N_("Implicit cartesian join attempted."));
470
603
  ADD_ERROR_MESSAGE(ER_ADMIN_ACCESS, N_("Admin access not allowed from this username/IP address."));
471
604
 
472
605
  // User lock/barrier error messages
481
614
 
482
615
  ADD_ERROR_MESSAGE(ER_INVALID_ALTER_TABLE_FOR_NOT_NULL, N_("Either a DEFAULt value or NULL NULL description is required for a new column if table is not empty"));
483
616
 
 
617
  // Cast errors
 
618
  ADD_ERROR_MESSAGE(ER_INVALID_CAST_TO_UNSIGNED, N_("Cast to unsigned converted negative integer to it's positive complement: %s"));
 
619
  ADD_ERROR_MESSAGE(ER_INVALID_CAST_TO_SIGNED, N_("Invalid cast to signed integer: %s"));
 
620
 
 
621
  ADD_ERROR_MESSAGE(ER_SQL_KEYWORD, N_("Identifier '%.*s' is a SQL keyword."));
 
622
 
484
623
 
485
624
  ADD_ERROR_MESSAGE(EE_CANTUNLOCK, N_("Can't unlock file (Errcode: %d)"));
486
625
  ADD_ERROR_MESSAGE(EE_CANT_CHSIZE, N_("Can't change size of file (Errcode: %d)"));
501
640
  ADD_ERROR_MESSAGE(ER_INVALID_UUID_VALUE, N_("Received an invalid UUID value"));
502
641
  ADD_ERROR_MESSAGE(ER_INVALID_UUID_TIME, N_("The UUID was not created with a valid time"));
503
642
 
 
643
  // For BOOL type
 
644
  ADD_ERROR_MESSAGE(ER_INVALID_BOOLEAN_VALUE, N_("Received an invalid BOOLEAN value '%s'."));
 
645
  ADD_ERROR_MESSAGE(ER_INVALID_CAST_TO_BOOLEAN, N_("Invalid cast to BOOLEAN: '%s'."));
 
646
 
 
647
  // Transactional DDL
 
648
  ADD_ERROR_MESSAGE(ER_TRANSACTIONAL_DDL_NOT_SUPPORTED, N_("Transactional DDL not supported"));
 
649
  // ASSERT Message
 
650
  ADD_ERROR_MESSAGE(ER_ASSERT, N_("Assertion '%s' failed."));
 
651
  ADD_ERROR_MESSAGE(ER_ASSERT_NULL, N_("Assertion '%s' failed, the result was NULL."));
 
652
 
504
653
  // Some old error values use the same strings as some new error values.
505
654
  ADD_ERROR_MESSAGE(EE_FILENOTFOUND, find(ER_FILE_NOT_FOUND));
506
655
  ADD_ERROR_MESSAGE(EE_CANTCREATEFILE, find(ER_CANT_CREATE_FILE));
515
664
  ADD_ERROR_MESSAGE(EE_DIR, find(ER_CANT_READ_DIR));
516
665
  ADD_ERROR_MESSAGE(EE_STAT, find(ER_CANT_GET_STAT));
517
666
  ADD_ERROR_MESSAGE(EE_DISK_FULL, find(ER_DISK_FULL));
518
 
 
 
667
  
 
668
  // Catalog related errors
 
669
  ADD_ERROR_MESSAGE(ER_CATALOG_CANNOT_CREATE, N_("Cannot create catalog '%s'."));
 
670
  ADD_ERROR_MESSAGE(ER_CATALOG_CANNOT_CREATE_PERMISSION, N_("Permission is denied to create '%s' catalog."));
 
671
  ADD_ERROR_MESSAGE(ER_CATALOG_CANNOT_DROP, N_("Cannot drop catalog '%s'."));
 
672
  ADD_ERROR_MESSAGE(ER_CATALOG_CANNOT_DROP_PERMISSION, N_("Permission is denied to drop '%s' catalog."));
 
673
  ADD_ERROR_MESSAGE(ER_CATALOG_DOES_NOT_EXIST, N_("Catalog '%s' does not exist."));
 
674
  ADD_ERROR_MESSAGE(ER_CATALOG_NO_DROP_LOCAL, N_("You cannot drop the 'local' catalog."));
 
675
  ADD_ERROR_MESSAGE(ER_CATALOG_NO_LOCK, N_("Could not gain lock on '%s'."));
 
676
  ADD_ERROR_MESSAGE(ER_CORRUPT_CATALOG_DEFINITION, N_("Corrupt or invalid catalog definition for '%s' : '%s'."));
 
677
  ADD_ERROR_MESSAGE(ER_WRONG_NAME_FOR_CATALOG, N_("Invalid catalog name."));
 
678
  ADD_ERROR_MESSAGE(ER_USE_DATA_DICTIONARY, N_("Engine status is now stored in the data_dictionary tables, please use these instead."));
 
679
  ADD_ERROR_MESSAGE(ER_TRANSACTION_ALREADY_STARTED, N_("There is already a transaction in progress"));
 
680
  ADD_ERROR_MESSAGE(ER_NO_LOCK_HELD, N_("No lock is held by this connection."));
519
681
}
520
682
 
521
683
} /* namespace drizzled */