Created
July 10, 2010 11:55
-
-
Save frsyuki/470667 to your computer and use it in GitHub Desktop.
MessagePack-RPCのエラー定義案
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#### | |
## Overview | |
## | |
# | |
# RPCError | |
# | | |
# +-- TimeoutError | |
# | | |
# +-- ClientError | |
# | | | |
# | +-- TransportError | |
# | | | | |
# | | +-- NetworkUnreachableError | |
# | | | | |
# | | +-- ConnectionRefusedError | |
# | | | | |
# | | +-- ConnectionTimeoutError | |
# | | | |
# | +-- MessageRefusedError | |
# | | | | |
# | | +-- MessageTooLargeError | |
# | | | |
# | +-- CallError | |
# | | | |
# | +-- NoMethodError | |
# | | | |
# | +-- ArgumentError | |
# | | |
# +-- ServerError | |
# | | | |
# | +-- ServerBusyError | |
# | | |
# +-- RemoteError | |
# | | |
# +-- RemoteRuntimeError | |
# | | |
# +-- (user-defined errors) | |
# | |
=begin | |
RPCError | |
| | |
+-- TimeoutError [code:-60, -6x] | |
| # サーバから応答を得られません。詳細はぜんぜん分かりません。 | |
| # メッセージは到達したかもしれません。 | |
| # リトライすると成功するかもしれません。 | |
| | |
+-- ClientError | |
| | # 要求に問題があるか、クライアントの設定ミスです。 | |
| | # あるいはネットワークの障害か設定ミスです。 | |
| | | |
| +-- TransportError [code:-50, -5x] | |
| | | # メッセージの転送を開始できませんでした。 | |
| | | # ネットワーク障害か設定ミス、またはハンドシェイクが成功しません。 | |
| | | | |
| | +-- NetworkUnreachableError [code:-51] | |
| | | # 指定されたアドレスに到達できません。 | |
| | | # 一部のトランスポートプロトコルでのみ検出されます。 | |
| | | | |
| | +-- ConnectionRefusedError [code:-52] | |
| | | # (TCP)コネクションの確立が明示的に拒否されました。 | |
| | | # リトライしてもきっと成功しません。 | |
| | | # コネクション指向のトランスポートプロトコルでのみ検出されます。 | |
| | | | |
| | +-- ConnectionTimeoutError [code:-53] | |
| | # (TCP)コネクションの確立がタイムアウトしました。 | |
| | # リトライすると成功するかもしれません。 | |
| | # コネクション指向のトランスポートプロトコルでのみ検出されます。 | |
| | | |
| +-- MessageRefusedError [code:-40, -4x] | |
| | | # メッセージの受信を明示的に拒否されました。 | |
| | | # | |
| | | # メッセージをデシリアライズできない | |
| | | # デシリアライズできたが構造がプロトコル的に間違っている | |
| | | # 構造も合っているが値がプロトコル的に間違っている | |
| | | # | |
| | | # 現象:デシリアライズできない | |
| | | # 現象:型が合わない(例:配列を想定しているのに整数を受け取った) | |
| | | # 現象:値が合わない(例:REQUESTを想定しているところにRESPONSEを受け取った) | |
| | | # 原因:ライブラリのバグ | |
| | | # 原因:デシリアライザのバージョンが合わない | |
| | | # 原因:RPCデシリアライザのバージョンが合わない | |
| | | # 原因:パケットが化けた | |
| | | | |
| | +-- MessageTooLargeError [code:-41] | |
| | # メッセージはサーバに拒否されました。 | |
| | # 構文は正しいかもしれません。 | |
| | # メッセージが大きすぎるか、メッセージが破損しています。 | |
| | # | |
| | # 現象:メッセージが大きすぎる(例:5000要素の配列を受け取った) | |
| | # 原因:デシリアライザのバージョンが合わない | |
| | # 原因:パケットが化けた | |
| | # 原因:アプリケーションが不正なメッセージを送ろうとした | |
| | # 原因:サーバの設定値が小さすぎる | |
| | | |
| +-- CallError [code:-20, -2x] | |
| | # メッセージは到達し、構造も妥当ですが、メソッドの呼び出しができません | |
| | | |
| +-- NoMethodError [code:-21] | |
| | # 指定されたメソッドが見つかりません。 | |
| | | |
| +-- ArgumentError [code:-22] | |
| # 引数の数か型に誤りがあります。 | |
| | |
+-- ServerError [code:-30, -3x] | |
| | # サーバは受け付けられたメッセージを一時的に処理できません。 | |
| | # 他のサーバなら処理できるかもしれません。 | |
| | | |
| +-- ServerBusyError [code:-31] | |
| # 過負荷のため要求をすぐに処理できません。 | |
| | |
+-- RemoteError [code:-1x] | |
| # メソッドを実行中にエラーが発生しました。 | |
| | |
+-- RemoteRuntimeError [code:-10] | |
| | |
+-- (ユーザー定義エラー) [code:0より大きい任意の然数] | |
=end | |
class Error < StandardError | |
end | |
class RPCError < Error | |
def initialize(msg, code) | |
super(msg) | |
@code = code | |
end | |
attr_reader :code | |
end | |
class TimeoutError < RPCError | |
CODE = -60 | |
def initialize(msg = "request timed out") | |
super(msg, CODE) | |
end | |
end | |
class ClientError < RPCError | |
def initialize(msg, code) | |
super(msg, code) | |
end | |
end | |
class TransportError < RPCError | |
CODE = -50 | |
def initialize(msg, code = CODE) | |
super(msg, CODE) | |
end | |
end | |
class NetworkUnreachableError < TransportError | |
CODE = -51 | |
def initialize(msg = "network unreachable") | |
super(msg, CODE) | |
end | |
end | |
class ConnectionRefusedError < TransportError | |
CODE = -52 | |
def initialize(msg = "connection refused") | |
super(msg, CODE) | |
end | |
end | |
class ConnectionTimeoutError < TransportError | |
CODE = -53 | |
def initialize(msg = "connection timed out") | |
super(msg, CODE) | |
end | |
end | |
class MessageRefusedError < ClientError | |
CODE = -40 | |
def initialize(msg = "broken message", code = CODE) | |
super(msg, code) | |
end | |
end | |
class MessageTooLargeError < MessageRefusedError | |
CODE = -41 | |
def initialize(msg = "messge too large") | |
super(msg, CODE) | |
end | |
end | |
class CallError < ClientError | |
CODE = -20 | |
def initialize(msg, code = CODE) | |
super(msg, code) | |
end | |
end | |
class NoMethodError < CallError | |
CODE = -21 | |
def initialize(msg = "method not found") | |
super(msg, CODE) | |
end | |
end | |
class ArgumentError < NoMethodError | |
CODE = -22 | |
def initialize(msg = "invalid argument") | |
super(msg, CODE) | |
end | |
end | |
class ServerError < RPCError | |
CODE = -30 | |
def initialize(msg, code = CODE) | |
super(msg, code) | |
end | |
end | |
class ServerBusyError < ServerError | |
CODE = -31 | |
def initialize(msg = "server temporally busy") | |
super(msg, CODE) | |
end | |
end | |
class RemoteError < RPCError | |
def initialize(msg, code, result = nil) | |
super(msg, code) | |
@result = result | |
end | |
attr_reader :result | |
end | |
class RemoteRuntimeError < RemoteRuntimeError | |
CODE = -10 | |
def initialize(msg, result = nil) | |
super(msg, CODE, result) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment