YUKI Hiroshi
null+****@clear*****
Wed Feb 19 16:11:14 JST 2014
YUKI Hiroshi 2014-02-19 16:11:14 +0900 (Wed, 19 Feb 2014) New Revision: b7079df743ff24379237dd25d399aa94862fde17 https://github.com/droonga/fluent-plugin-droonga/commit/b7079df743ff24379237dd25d399aa94862fde17 Message: Define error message classes under ErrorMessages instead of ErrorMessage Modified files: lib/droonga/catalog/base.rb lib/droonga/dispatcher.rb lib/droonga/distributed_command_planner.rb lib/droonga/error.rb lib/droonga/handler_runner.rb lib/droonga/plugins/crud.rb lib/droonga/plugins/error.rb lib/droonga/searcher.rb Renamed files: lib/droonga/error_messages.rb (from lib/droonga/error_message.rb) Modified: lib/droonga/catalog/base.rb (+1 -1) =================================================================== --- lib/droonga/catalog/base.rb 2014-02-19 15:54:56 +0900 (03464b4) +++ lib/droonga/catalog/base.rb 2014-02-19 16:11:14 +0900 (256cf0e) @@ -16,7 +16,7 @@ require "digest/sha1" require "zlib" require "time" -require "droonga/error_message" +require "droonga/error_messages" require "droonga/catalog/errors" module Droonga Modified: lib/droonga/dispatcher.rb (+6 -6) =================================================================== --- lib/droonga/dispatcher.rb 2014-02-19 15:54:56 +0900 (490ec87) +++ lib/droonga/dispatcher.rb 2014-02-19 16:11:14 +0900 (552f100) @@ -22,26 +22,26 @@ require "droonga/collector_runner" require "droonga/farm" require "droonga/session" require "droonga/replier" -require "droonga/error_message" +require "droonga/error_messages" require "droonga/distributor" module Droonga class Dispatcher attr_reader :name - class MissingDatasetParameter < ErrorMessage::BadRequest + class MissingDatasetParameter < ErrorMessages::BadRequest def initialize super("\"dataset\" must be specified.") end end - class UnknownDataset < ErrorMessage::NotFound + class UnknownDataset < ErrorMessages::NotFound def initialize(dataset) super("The dataset #{dataset.inspect} does not exist.") end end - class UnknownCommand < ErrorMessage::BadRequest + class UnknownCommand < ErrorMessages::BadRequest def initialize(command, dataset) super("The command #{command.inspect} is not available " + "for the dataset #{dataset.inspect}.") @@ -96,12 +96,12 @@ module Droonga begin assert_valid_message(message) process_input_message(message) - rescue ErrorMessage::Error => error + rescue ErrorMessages::Error => error reply("statusCode" => error.status_code, "body" => error.response_body) rescue StandardError, LoadError, SyntaxError => error Logger.error("failed to process input message", error) - formatted_error = ErrorMessage::InternalServerError.new("Unknown internal error") + formatted_error = ErrorMessages::InternalServerError.new("Unknown internal error") reply("statusCode" => formatted_error.status_code, "body" => formatted_error.response_body) raise error Modified: lib/droonga/distributed_command_planner.rb (+1 -1) =================================================================== --- lib/droonga/distributed_command_planner.rb 2014-02-19 15:54:56 +0900 (f492641) +++ lib/droonga/distributed_command_planner.rb 2014-02-19 16:11:14 +0900 (cfb806f) @@ -127,7 +127,7 @@ module Droonga def fixed_processor @processor["outputs"] = @outputs if @processor["type"] == "scatter" - raise ErrorMessage::InternalServerError.new("missing key") unless @key + raise ErrorMessages::InternalServerError.new("missing key") unless @key @processor["key"] = @key end @processor Modified: lib/droonga/error.rb (+29 -0) =================================================================== --- lib/droonga/error.rb 2014-02-19 15:54:56 +0900 (39f8a49) +++ lib/droonga/error.rb 2014-02-19 16:11:14 +0900 (41e6f6d) @@ -32,6 +32,35 @@ module Droonga end end + # the base class for any error which can be described as a Droonga message + class ErrorMessage < Error + STATUS_CODE = nil + + attr_reader :detail + + def initialize(message, detail=nil) + @detail = detail + super(message) + end + + def name + self.class.name.split("::").last + end + + def status_code + self.class::STATUS_CODE + end + + def response_body + body = { + "name" => name, + "message" => message, + } + body["detail"] = @detail unles****@detai*****? + body + end + end + # TODO: Move to common file for runners class UnsupportedMessageError < Error attr_reader :phase, :message Renamed: lib/droonga/error_messages.rb (+4 -32) 60% =================================================================== --- lib/droonga/error_message.rb 2014-02-19 15:54:56 +0900 (bf11b24) +++ lib/droonga/error_messages.rb 2014-02-19 16:11:14 +0900 (58d355e) @@ -17,44 +17,16 @@ require "droonga/error" require "droonga/status_code" module Droonga - module ErrorMessage - class Error < Droonga::Error - STATUS_CODE = nil - - attr_reader :detail - - def initialize(message, detail=nil) - @detail = detail - super(message) - end - - def name - self.class.name.split("::").last - end - - def status_code - self.class::STATUS_CODE - end - - def response_body - body = { - "name" => name, - "message" => message, - } - body["detail"] = @detail unles****@detai*****? - body - end - end - - class InternalServerError < Error + module ErrorMessages + class InternalServerError < ErrorMessage STATUS_CODE = StatusCode::INTERNAL_SERVER_ERROR end - class BadRequest < Error + class BadRequest < ErrorMessage STATUS_CODE = StatusCode::BAD_REQUEST end - class NotFound < Error + class NotFound < ErrorMessage STATUS_CODE = StatusCode::NOT_FOUND end end Modified: lib/droonga/handler_runner.rb (+1 -1) =================================================================== --- lib/droonga/handler_runner.rb 2014-02-19 15:54:56 +0900 (0338f5f) +++ lib/droonga/handler_runner.rb 2014-02-19 16:11:14 +0900 (3d6a72c) @@ -96,7 +96,7 @@ module Droonga handler = handler_class.new(@name, @context) begin handler.handle(handler_message, messenger) - rescue ErrorMessage::Error => error + rescue ErrorMessage => error messenger.error(error.status_code, error.response_body) end end Modified: lib/droonga/plugins/crud.rb (+6 -6) =================================================================== --- lib/droonga/plugins/crud.rb 2014-02-19 15:54:56 +0900 (5694043) +++ lib/droonga/plugins/crud.rb 2014-02-19 16:11:14 +0900 (11ec426) @@ -16,7 +16,7 @@ require "groonga" require "droonga/plugin" -require "droonga/error_message" +require "droonga/error_messages" module Droonga module Plugins @@ -50,33 +50,33 @@ module Droonga class Handler < Droonga::Handler message.type = "add" - class MissingTableParameter < ErrorMessage::BadRequest + class MissingTableParameter < ErrorMessages::BadRequest def initialize super("\"table\" must be specified.") end end - class MissingPrimaryKeyParameter < ErrorMessage::BadRequest + class MissingPrimaryKeyParameter < ErrorMessages::BadRequest def initialize(table_name) super("\"key\" must be specified. " + "The table #{table_name.inspect} requires a primary key for a new record.") end end - class UnknownTable < ErrorMessage::NotFound + class UnknownTable < ErrorMessages::NotFound def initialize(table_name) super("The table #{table_name.inspect} does not exist in the dataset.") end end - class InvalidValue < ErrorMessage::BadRequest + class InvalidValue < ErrorMessages::BadRequest def initialize(column, value, request) super("The column #{column.inspect} cannot store the value #{value.inspect}.", request) end end - class UnknownColumn < ErrorMessage::NotFound + class UnknownColumn < ErrorMessages::NotFound def initialize(column, table, request) super("The column #{column.inspect} does not exist in the table #{table.inspect}.", request) Modified: lib/droonga/plugins/error.rb (+1 -1) =================================================================== --- lib/droonga/plugins/error.rb 2014-02-19 15:54:56 +0900 (9435dca) +++ lib/droonga/plugins/error.rb 2014-02-19 16:11:14 +0900 (8ba6342) @@ -36,7 +36,7 @@ module Droonga if status_codes.size == 1 output_message.status_code = status_codes.first else - output_message.status_code = ErrorMessage::InternalServerError::STATUS_CODE + output_message.status_code = ErrorMessages::InternalServerError::STATUS_CODE end output_message.body = errors.values.first["body"] Modified: lib/droonga/searcher.rb (+5 -5) =================================================================== --- lib/droonga/searcher.rb 2014-02-19 15:54:56 +0900 (f585cd7) +++ lib/droonga/searcher.rb 2014-02-19 16:11:14 +0900 (574d08d) @@ -20,17 +20,17 @@ require "tsort" require "groonga" require "droonga/time_formatter" -require "droonga/error_message" +require "droonga/error_messages" module Droonga class Searcher - class NoQuery < ErrorMessage::BadRequest + class NoQuery < ErrorMessages::BadRequest def initialize super("You must specify one or more query.") end end - class MissingSourceParameter < ErrorMessage::BadRequest + class MissingSourceParameter < ErrorMessages::BadRequest def initialize(query, queries) super("The query #{query.inspect} has no source. " + "Query must have a valid source.", @@ -38,7 +38,7 @@ module Droonga end end - class UnknownSource < ErrorMessage::NotFound + class UnknownSource < ErrorMessages::NotFound def initialize(source, queries) super("The source #{source.inspect} does not exist. " + "It must be a name of an existing table or another query.", @@ -46,7 +46,7 @@ module Droonga end end - class CyclicSource < ErrorMessage::BadRequest + class CyclicSource < ErrorMessages::BadRequest def initialize(queries) super("There is cyclic reference of sources.", queries) -------------- next part -------------- HTML����������������������������...Download