Skip to content

Commit 5a7ab22

Browse files
committed
Update error codes to remove application specific ones
These were either not errors at all (just range definitions) or were in the application specific range, so not appropriate to keep in a more general library.
1 parent be79004 commit 5a7ab22

File tree

2 files changed

+22
-13
lines changed

2 files changed

+22
-13
lines changed

src/core.jl

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,28 @@ struct JSONRPCError <: Exception
1616
data::Any
1717
end
1818

19+
"""
20+
SERVER_ERROR_END
21+
22+
The end of the range of server-reserved errors.
23+
24+
These are JSON-RPC server errors that are free for the taking
25+
for JSON-RPC server implementations. Applications making use of
26+
this library should NOT define new errors in this range.
27+
"""
28+
const SERVER_ERROR_END = -32000
29+
30+
"""
31+
SERVER_ERROR_START
32+
33+
The start of the range of server-reserved errors.
34+
35+
These are JSON-RPC server errors that are free for the taking
36+
for JSON-RPC server implementations. Applications making use of
37+
this library should NOT define new errors in this range.
38+
"""
39+
const SERVER_ERROR_START = -32099
40+
1941
"""
2042
PARSE_ERROR
2143
@@ -52,10 +74,6 @@ Internal JSON-RPC error.
5274
"""
5375
const INTERNAL_ERROR = -32603
5476

55-
# these are the reserved endpoints of JSON-RPC error codes
56-
const SERVER_ERROR_END = -32000
57-
const SERVER_ERROR_START = -32099
58-
5977
"""
6078
RPCErrorStrings
6179
@@ -70,13 +88,8 @@ const RPCErrorStrings = Base.IdDict(
7088
INVALID_PARAMS => "InvalidParams",
7189
INTERNAL_ERROR => "InternalError",
7290
[ i => "ServerError" for i in SERVER_ERROR_START:SERVER_ERROR_END]...,
73-
# TODO: these should be removed - they are in the application/implementation specific range
74-
-32000 => "serverErrorEnd",
75-
-32099 => "serverErrorStart",
7691
-32002 => "ServerNotInitialized",
7792
-32001 => "UnknownErrorCode",
78-
-32800 => "RequestCancelled",
79-
-32801 => "ContentModified"
8093
)
8194

8295
function Base.showerror(io::IO, ex::JSONRPCError)

test/test_core.jl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,7 @@
44
@test sprint(showerror, JSONRPC.JSONRPCError(-32601, "FOO", "BAR")) == "MethodNotFound: FOO (BAR)"
55
@test sprint(showerror, JSONRPC.JSONRPCError(-32602, "FOO", "BAR")) == "InvalidParams: FOO (BAR)"
66
@test sprint(showerror, JSONRPC.JSONRPCError(-32603, "FOO", "BAR")) == "InternalError: FOO (BAR)"
7-
@test sprint(showerror, JSONRPC.JSONRPCError(-32099, "FOO", "BAR")) == "serverErrorStart: FOO (BAR)"
8-
@test sprint(showerror, JSONRPC.JSONRPCError(-32000, "FOO", "BAR")) == "serverErrorEnd: FOO (BAR)"
97
@test sprint(showerror, JSONRPC.JSONRPCError(-32002, "FOO", "BAR")) == "ServerNotInitialized: FOO (BAR)"
108
@test sprint(showerror, JSONRPC.JSONRPCError(-32001, "FOO", "BAR")) == "UnknownErrorCode: FOO (BAR)"
11-
@test sprint(showerror, JSONRPC.JSONRPCError(-32800, "FOO", "BAR")) == "RequestCancelled: FOO (BAR)"
12-
@test sprint(showerror, JSONRPC.JSONRPCError(-32801, "FOO", "BAR")) == "ContentModified: FOO (BAR)"
139
@test sprint(showerror, JSONRPC.JSONRPCError(1, "FOO", "BAR")) == "Unknown: FOO (BAR)"
1410
end

0 commit comments

Comments
 (0)