void grn_query_logger_put(grn_ctx *ctx, unsigned int flag, const char *mark, const char *format, ...) { char timestamp[TIMESTAMP_BUFFER_SIZE]; char info[INFO_BUFFER_SIZE]; grn_obj *message = &ctx->impl->query_log_buf; if (!current_query_logger.log) { return; } { grn_timeval tv; timestamp[0] = '\0'; grn_timeval_now(ctx, &tv); grn_timeval2str(ctx, &tv, timestamp, TIMESTAMP_BUFFER_SIZE); } if (flag & (GRN_QUERY_LOG_COMMAND | GRN_QUERY_LOG_DESTINATION)) { grn_snprintf(info, INFO_BUFFER_SIZE, INFO_BUFFER_SIZE, "%p|%s", ctx, mark); info[INFO_BUFFER_SIZE - 1] = '\0'; } else { grn_timeval tv; uint64_t elapsed_time; grn_timeval_now(ctx, &tv); elapsed_time = (uint64_t)(tv.tv_sec - ctx->impl->tv.tv_sec) * GRN_TIME_NSEC_PER_SEC + (tv.tv_nsec - ctx->impl->tv.tv_nsec); grn_snprintf(info, INFO_BUFFER_SIZE, INFO_BUFFER_SIZE, "%p|%s%015" GRN_FMT_INT64U " ", ctx, mark, elapsed_time); info[INFO_BUFFER_SIZE - 1] = '\0'; } { va_list args; va_start(args, format); GRN_BULK_REWIND(message); grn_text_vprintf(ctx, message, format, args); va_end(args); GRN_TEXT_PUTC(ctx, message, '\0'); } current_query_logger.log(ctx, flag, timestamp, info, GRN_TEXT_VALUE(message), current_query_logger.user_data); }
void grn_logger_putv(grn_ctx *ctx, grn_log_level level, const char *file, int line, const char *func, const char *fmt, va_list ap) { if (level <= current_logger.max_level && current_logger.log) { char tbuf[TBUFSIZE]; char mbuf[MBUFSIZE]; char lbuf[LBUFSIZE]; tbuf[0] = '\0'; if (current_logger.flags & GRN_LOG_TIME) { grn_timeval tv; grn_timeval_now(ctx, &tv); grn_timeval2str(ctx, &tv, tbuf, TBUFSIZE); } if (current_logger.flags & GRN_LOG_MESSAGE) { grn_vsnprintf(mbuf, MBUFSIZE, fmt, ap); } else { mbuf[0] = '\0'; } if (current_logger.flags & GRN_LOG_LOCATION) { grn_snprintf(lbuf, LBUFSIZE, LBUFSIZE, "%d %s:%d %s()", getpid(), file, line, func); } else { lbuf[0] = '\0'; } current_logger.log(ctx, level, tbuf, "", mbuf, lbuf, current_logger.user_data); } }
grn_rc grn_timeval2str(grn_ctx *ctx, grn_timeval *tv, char *buf, size_t buf_size) { struct tm tm; struct tm *ltm; ltm = grn_timeval2tm(ctx, tv, &tm); grn_snprintf(buf, buf_size, GRN_TIMEVAL_STR_SIZE, GRN_TIMEVAL_STR_FORMAT, ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour, ltm->tm_min, ltm->tm_sec, (int)(GRN_TIME_NSEC_TO_USEC(tv->tv_nsec))); if (buf_size > GRN_TIMEVAL_STR_SIZE) { buf[GRN_TIMEVAL_STR_SIZE - 1] = '\0'; } else { buf[buf_size - 1] = '\0'; } return ctx->rc; }
static void rotate_log_file(grn_ctx *ctx, const char *current_path) { char rotated_path[PATH_MAX]; grn_timeval now; struct tm tm_buffer; struct tm *tm; grn_timeval_now(ctx, &now); tm = grn_timeval2tm(ctx, &now, &tm_buffer); grn_snprintf(rotated_path, PATH_MAX, PATH_MAX, "%s.%04d-%02d-%02d-%02d-%02d-%02d-%06d", current_path, tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec, (int)(GRN_TIME_NSEC_TO_USEC(now.tv_nsec))); rename(current_path, rotated_path); }
mrb_value grn_mrb_value_from_bulk(mrb_state *mrb, grn_obj *bulk) { mrb_value mrb_value_; grn_ctx *ctx = (grn_ctx *)mrb->ud; switch (bulk->header.domain) { case GRN_DB_INT32 : { int32_t value; value = GRN_INT32_VALUE(bulk); mrb_value_ = mrb_fixnum_value(value); } break; case GRN_DB_UINT32 : { int64_t value; value = GRN_UINT32_VALUE(bulk); if (!FIXABLE(value)) { mrb_raisef(mrb, E_RANGE_ERROR, "can't handle large number: <%S>: max: <%S>", mrb_fixnum_value(value), /* TODO: This will cause overflow */ mrb_fixnum_value(MRB_INT_MAX)); } mrb_value_ = mrb_fixnum_value(value); } break; case GRN_DB_TIME : { int64_t value; int32_t sec; int32_t usec; value = GRN_TIME_VALUE(bulk); GRN_TIME_UNPACK(value, sec, usec); mrb_value_ = mrb_funcall(mrb, mrb_obj_value(ctx->impl->mrb.builtin.time_class), "at", 2, mrb_fixnum_value(sec), mrb_fixnum_value(usec)); } break; case GRN_DB_SHORT_TEXT : case GRN_DB_TEXT : case GRN_DB_LONG_TEXT : mrb_value_ = mrb_str_new(mrb, GRN_TEXT_VALUE(bulk), GRN_TEXT_LEN(bulk)); break; default : { grn_obj *domain; grn_bool is_record = GRN_FALSE; domain = grn_ctx_at(ctx, bulk->header.domain); if (domain) { switch (domain->header.type) { case GRN_TABLE_HASH_KEY : case GRN_TABLE_PAT_KEY : case GRN_TABLE_DAT_KEY : case GRN_TABLE_NO_KEY : is_record = GRN_TRUE; break; default : break; } } if (is_record) { mrb_value_ = mrb_fixnum_value(GRN_RECORD_VALUE(bulk)); grn_obj_unlink(ctx, domain); } else { #define MESSAGE_SIZE 4096 char message[MESSAGE_SIZE]; char domain_name[GRN_TABLE_MAX_KEY_SIZE]; int domain_name_size; if (domain) { domain_name_size = grn_obj_name(ctx, domain, domain_name, GRN_TABLE_MAX_KEY_SIZE); grn_obj_unlink(ctx, domain); } else { grn_strcpy(domain_name, GRN_TABLE_MAX_KEY_SIZE, "unknown"); domain_name_size = strlen(domain_name); } grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "unsupported bulk value type: <%d>(%.*s)", bulk->header.domain, domain_name_size, domain_name); mrb_raise(mrb, E_RANGE_ERROR, message); } #undef MESSAGE_SIZE } break; } return mrb_value_; }
struct RClass * grn_mrb_class_from_grn_obj(mrb_state *mrb, grn_obj *object) { grn_ctx *ctx = (grn_ctx *)mrb->ud; grn_mrb_data *data; struct RClass *klass = NULL; data = &(ctx->impl->mrb); switch (object->header.type) { case GRN_BULK : klass = mrb_class_get_under(mrb, data->module, "Bulk"); break; case GRN_ACCESSOR : klass = mrb_class_get_under(mrb, data->module, "Accessor"); break; case GRN_COLUMN_FIX_SIZE : klass = mrb_class_get_under(mrb, data->module, "FixedSizeColumn"); break; case GRN_COLUMN_VAR_SIZE : klass = mrb_class_get_under(mrb, data->module, "VariableSizeColumn"); break; case GRN_COLUMN_INDEX : klass = mrb_class_get_under(mrb, data->module, "IndexColumn"); break; case GRN_TYPE : klass = mrb_class_get_under(mrb, data->module, "Type"); break; case GRN_PROC : klass = mrb_class_get_under(mrb, data->module, "Procedure"); break; case GRN_EXPR : klass = mrb_class_get_under(mrb, data->module, "Expression"); break; case GRN_TABLE_NO_KEY : klass = mrb_class_get_under(mrb, data->module, "Array"); break; case GRN_TABLE_HASH_KEY : klass = mrb_class_get_under(mrb, data->module, "HashTable"); break; case GRN_TABLE_PAT_KEY : klass = mrb_class_get_under(mrb, data->module, "PatriciaTrie"); break; case GRN_TABLE_DAT_KEY : klass = mrb_class_get_under(mrb, data->module, "DoubleArrayTrie"); break; case GRN_DB : klass = mrb_class_get_under(mrb, data->module, "Database"); break; case GRN_VOID : klass = mrb_class_get_under(mrb, data->module, "Void"); break; default : break; } if (!klass) { #define BUFFER_SIZE 1024 char buffer[BUFFER_SIZE]; grn_snprintf(buffer, BUFFER_SIZE, BUFFER_SIZE, "can't find class for object type: %#x", object->header.type); mrb_raise(mrb, E_ARGUMENT_ERROR, buffer); #undef BUFFER_SIZE } return klass; }
grn_obj * grn_inspect_type(grn_ctx *ctx, grn_obj *buf, unsigned char type) { switch (type) { case GRN_VOID : GRN_TEXT_PUTS(ctx, buf, "GRN_VOID"); break; case GRN_BULK : GRN_TEXT_PUTS(ctx, buf, "GRN_BULK"); break; case GRN_PTR : GRN_TEXT_PUTS(ctx, buf, "GRN_PTR"); break; case GRN_UVECTOR : GRN_TEXT_PUTS(ctx, buf, "GRN_UVECTOR"); break; case GRN_PVECTOR : GRN_TEXT_PUTS(ctx, buf, "GRN_PVECTOR"); break; case GRN_VECTOR : GRN_TEXT_PUTS(ctx, buf, "GRN_VECTOR"); break; case GRN_MSG : GRN_TEXT_PUTS(ctx, buf, "GRN_MSG"); break; case GRN_QUERY : GRN_TEXT_PUTS(ctx, buf, "GRN_QUERY"); break; case GRN_ACCESSOR : GRN_TEXT_PUTS(ctx, buf, "GRN_ACCESSOR"); break; case GRN_SNIP : GRN_TEXT_PUTS(ctx, buf, "GRN_SNIP"); break; case GRN_PATSNIP : GRN_TEXT_PUTS(ctx, buf, "GRN_PATSNIP"); break; case GRN_STRING : GRN_TEXT_PUTS(ctx, buf, "GRN_STRING"); break; case GRN_CURSOR_TABLE_HASH_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_CURSOR_TABLE_HASH_KEY"); break; case GRN_CURSOR_TABLE_PAT_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_CURSOR_TABLE_PAT_KEY"); break; case GRN_CURSOR_TABLE_DAT_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_CURSOR_TABLE_DAT_KEY"); break; case GRN_CURSOR_TABLE_NO_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_CURSOR_TABLE_NO_KEY"); break; case GRN_CURSOR_COLUMN_INDEX : GRN_TEXT_PUTS(ctx, buf, "GRN_CURSOR_COLUMN_INDEX"); break; case GRN_CURSOR_COLUMN_GEO_INDEX : GRN_TEXT_PUTS(ctx, buf, "GRN_CURSOR_COLUMN_GEO_INDEX"); break; case GRN_TYPE : GRN_TEXT_PUTS(ctx, buf, "GRN_TYPE"); break; case GRN_PROC : GRN_TEXT_PUTS(ctx, buf, "GRN_PROC"); break; case GRN_EXPR : GRN_TEXT_PUTS(ctx, buf, "GRN_EXPR"); break; case GRN_TABLE_HASH_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_TABLE_HASH_KEY"); break; case GRN_TABLE_PAT_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_TABLE_PAT_KEY"); break; case GRN_TABLE_DAT_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_TABLE_DAT_KEY"); break; case GRN_TABLE_NO_KEY : GRN_TEXT_PUTS(ctx, buf, "GRN_TABLE_NO_KEY"); break; case GRN_DB : GRN_TEXT_PUTS(ctx, buf, "GRN_DB"); break; case GRN_COLUMN_FIX_SIZE : GRN_TEXT_PUTS(ctx, buf, "GRN_COLUMN_FIX_SIZE"); break; case GRN_COLUMN_VAR_SIZE : GRN_TEXT_PUTS(ctx, buf, "GRN_COLUMN_VAR_SIZE"); break; case GRN_COLUMN_INDEX : GRN_TEXT_PUTS(ctx, buf, "GRN_COLUMN_INDEX"); break; default: { #define TYPE_IN_HEX_SIZE 5 /* "0xXX" */ char type_in_hex[TYPE_IN_HEX_SIZE]; grn_snprintf(type_in_hex, TYPE_IN_HEX_SIZE, TYPE_IN_HEX_SIZE, "%#02x", type); #undef TYPE_IN_HEX_SIZE GRN_TEXT_PUTS(ctx, buf, "(unknown: "); GRN_TEXT_PUTS(ctx, buf, type_in_hex); GRN_TEXT_PUTS(ctx, buf, ")"); } break; } return buf; }
void grn_mrb_ctx_check(mrb_state *mrb) { grn_ctx *ctx = (grn_ctx *)mrb->ud; grn_mrb_data *data = &(ctx->impl->mrb); struct RClass *module = data->module; struct RClass *error_class; #define MESSAGE_SIZE 4096 char message[MESSAGE_SIZE]; switch (ctx->rc) { case GRN_SUCCESS: return; case GRN_END_OF_DATA: error_class = mrb_class_get_under(mrb, module, "EndOfData"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "end of data: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_UNKNOWN_ERROR: error_class = mrb_class_get_under(mrb, module, "UnknownError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "unknown error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_OPERATION_NOT_PERMITTED: error_class = mrb_class_get_under(mrb, module, "OperationNotPermitted"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "operation not permitted: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_FILE_OR_DIRECTORY: error_class = mrb_class_get_under(mrb, module, "NoSuchFileOrDirectory"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no such file or directory: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_PROCESS: error_class = mrb_class_get_under(mrb, module, "NoSuchProcess"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no such process: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INTERRUPTED_FUNCTION_CALL: error_class = mrb_class_get_under(mrb, module, "InterruptedFunctionCall"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "interrupted function call: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INPUT_OUTPUT_ERROR: error_class = mrb_class_get_under(mrb, module, "InputOutputError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "input output error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_DEVICE_OR_ADDRESS: error_class = mrb_class_get_under(mrb, module, "NoSuchDeviceOrAddress"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no such device or address: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_ARG_LIST_TOO_LONG: error_class = mrb_class_get_under(mrb, module, "ArgListTooLong"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "arg list too long: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_EXEC_FORMAT_ERROR: error_class = mrb_class_get_under(mrb, module, "ExecFormatError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "exec format error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_BAD_FILE_DESCRIPTOR: error_class = mrb_class_get_under(mrb, module, "BadFileDescriptor"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "bad file descriptor: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_CHILD_PROCESSES: error_class = mrb_class_get_under(mrb, module, "NoChildProcesses"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no child processes: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_RESOURCE_TEMPORARILY_UNAVAILABLE: error_class = mrb_class_get_under(mrb, module, "ResourceTemporarilyUnavailable"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "resource temporarily unavailable: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NOT_ENOUGH_SPACE: error_class = mrb_class_get_under(mrb, module, "NotEnoughSpace"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "not enough space: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_PERMISSION_DENIED: error_class = mrb_class_get_under(mrb, module, "PermissionDenied"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "permission denied: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_BAD_ADDRESS: error_class = mrb_class_get_under(mrb, module, "BadAddress"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "bad address: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_RESOURCE_BUSY: error_class = mrb_class_get_under(mrb, module, "ResourceBusy"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "resource busy: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_FILE_EXISTS: error_class = mrb_class_get_under(mrb, module, "FileExists"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "file exists: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_IMPROPER_LINK: error_class = mrb_class_get_under(mrb, module, "ImproperLink"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "improper link: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_SUCH_DEVICE: error_class = mrb_class_get_under(mrb, module, "NoSuchDevice"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no such device: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NOT_A_DIRECTORY: error_class = mrb_class_get_under(mrb, module, "NotDirectory"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "not directory: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_IS_A_DIRECTORY: error_class = mrb_class_get_under(mrb, module, "IsDirectory"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "is directory: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INVALID_ARGUMENT: error_class = mrb_class_get_under(mrb, module, "InvalidArgument"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "invalid argument: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_OPEN_FILES_IN_SYSTEM: error_class = mrb_class_get_under(mrb, module, "TooManyOpenFilesInSystem"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too many open files in system: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_OPEN_FILES: error_class = mrb_class_get_under(mrb, module, "TooManyOpenFiles"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too many open files: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INAPPROPRIATE_I_O_CONTROL_OPERATION: error_class = mrb_class_get_under(mrb, module, "InappropriateIOControlOperation"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "inappropriate IO control operation: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_FILE_TOO_LARGE: error_class = mrb_class_get_under(mrb, module, "FileTooLarge"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "file too large: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_SPACE_LEFT_ON_DEVICE: error_class = mrb_class_get_under(mrb, module, "NoSpaceLeftOnDevice"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no space left on device: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INVALID_SEEK: error_class = mrb_class_get_under(mrb, module, "InvalidSeek"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "invalid seek: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_READ_ONLY_FILE_SYSTEM: error_class = mrb_class_get_under(mrb, module, "ReadOnlyFileSystem"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "read only file system: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_LINKS: error_class = mrb_class_get_under(mrb, module, "TooManyLinks"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too many links: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_BROKEN_PIPE: error_class = mrb_class_get_under(mrb, module, "BrokenPipe"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "broken pipe: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_DOMAIN_ERROR: error_class = mrb_class_get_under(mrb, module, "DomainError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "domain error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_RESULT_TOO_LARGE: error_class = mrb_class_get_under(mrb, module, "ResultTooLarge"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "result too large: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_RESOURCE_DEADLOCK_AVOIDED: error_class = mrb_class_get_under(mrb, module, "ResourceDeadlockAvoided"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "resource deadlock avoided: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_MEMORY_AVAILABLE: error_class = mrb_class_get_under(mrb, module, "NoMemoryAvailable"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no memory available: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_FILENAME_TOO_LONG: error_class = mrb_class_get_under(mrb, module, "FilenameTooLong"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "filename too long: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_LOCKS_AVAILABLE: error_class = mrb_class_get_under(mrb, module, "NoLocksAvailable"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no locks available: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_FUNCTION_NOT_IMPLEMENTED: error_class = mrb_class_get_under(mrb, module, "FunctionNotImplemented"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "function not implemented: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_DIRECTORY_NOT_EMPTY: error_class = mrb_class_get_under(mrb, module, "DirectoryNotEmpty"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "directory not empty: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_ILLEGAL_BYTE_SEQUENCE: error_class = mrb_class_get_under(mrb, module, "IllegalByteSequence"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "illegal byte sequence: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_SOCKET_NOT_INITIALIZED: error_class = mrb_class_get_under(mrb, module, "SocketNotInitialized"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "socket not initialized: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_OPERATION_WOULD_BLOCK: error_class = mrb_class_get_under(mrb, module, "OperationWouldBlock"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "operation would block: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_ADDRESS_IS_NOT_AVAILABLE: error_class = mrb_class_get_under(mrb, module, "AddressIsNotAvailable"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "address is not available: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NETWORK_IS_DOWN: error_class = mrb_class_get_under(mrb, module, "NetworkIsDown"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "network is down: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NO_BUFFER: error_class = mrb_class_get_under(mrb, module, "NoBuffer"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "no buffer: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_SOCKET_IS_ALREADY_CONNECTED: error_class = mrb_class_get_under(mrb, module, "SocketIsAlreadyConnected"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "socket is already connected: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_SOCKET_IS_NOT_CONNECTED: error_class = mrb_class_get_under(mrb, module, "SocketIsNotConnected"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "socket is not connected: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_SOCKET_IS_ALREADY_SHUTDOWNED: error_class = mrb_class_get_under(mrb, module, "SocketIsAlreadyShutdowned"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "socket is already shutdowned: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_OPERATION_TIMEOUT: error_class = mrb_class_get_under(mrb, module, "OperationTimeout"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "operation timeout: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_CONNECTION_REFUSED: error_class = mrb_class_get_under(mrb, module, "ConnectionRefused"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "connection refused: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_RANGE_ERROR: error_class = mrb_class_get_under(mrb, module, "RangeError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "range error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOKENIZER_ERROR: error_class = mrb_class_get_under(mrb, module, "TokenizerError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "tokenizer error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_FILE_CORRUPT: error_class = mrb_class_get_under(mrb, module, "FileCorrupt"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "file corrupt: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INVALID_FORMAT: error_class = mrb_class_get_under(mrb, module, "InvalidFormat"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "invalid format: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_OBJECT_CORRUPT: error_class = mrb_class_get_under(mrb, module, "ObjectCorrupt"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "object corrupt: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_MANY_SYMBOLIC_LINKS: error_class = mrb_class_get_under(mrb, module, "TooManySymbolicLinks"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too many symbolic links: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NOT_SOCKET: error_class = mrb_class_get_under(mrb, module, "NotSocket"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "not socket: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_OPERATION_NOT_SUPPORTED: error_class = mrb_class_get_under(mrb, module, "OperationNotSupported"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "operation not supported: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_ADDRESS_IS_IN_USE: error_class = mrb_class_get_under(mrb, module, "AddressIsInUse"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "address is in use: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_ZLIB_ERROR: error_class = mrb_class_get_under(mrb, module, "ZlibError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "zlib error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_LZ4_ERROR: error_class = mrb_class_get_under(mrb, module, "LZ4Error"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "LZ4 error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_STACK_OVER_FLOW: error_class = mrb_class_get_under(mrb, module, "StackOverFlow"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "stack over flow: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_SYNTAX_ERROR: error_class = mrb_class_get_under(mrb, module, "SyntaxError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "syntax error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_RETRY_MAX: error_class = mrb_class_get_under(mrb, module, "RetryMax"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "retry max: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_INCOMPATIBLE_FILE_FORMAT: error_class = mrb_class_get_under(mrb, module, "IncompatibleFileFormat"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "incompatible file format: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_UPDATE_NOT_ALLOWED: error_class = mrb_class_get_under(mrb, module, "UpdateNotAllowed"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "update not allowed: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_SMALL_OFFSET: error_class = mrb_class_get_under(mrb, module, "TooSmallOffset"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too small offset: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_LARGE_OFFSET: error_class = mrb_class_get_under(mrb, module, "TooLargeOffset"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too large offset: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_TOO_SMALL_LIMIT: error_class = mrb_class_get_under(mrb, module, "TooSmallLimit"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "too small limit: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_CAS_ERROR: error_class = mrb_class_get_under(mrb, module, "CASError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "CAS error: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_UNSUPPORTED_COMMAND_VERSION: error_class = mrb_class_get_under(mrb, module, "UnsupportedCommandVersion"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "unsupported command version: <%s>(%d)", ctx->errbuf, ctx->rc); break; case GRN_NORMALIZER_ERROR: error_class = mrb_class_get_under(mrb, module, "NormalizerError"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "normalizer error: <%s>(%d)", ctx->errbuf, ctx->rc); break; default: error_class = mrb_class_get_under(mrb, module, "Error"); grn_snprintf(message, MESSAGE_SIZE, MESSAGE_SIZE, "unsupported error: <%s>(%d)", ctx->errbuf, ctx->rc); break; } #undef MESSAGE_SIZE mrb_raise(mrb, error_class, message); }