Skip to content

Commit b1c0a3a

Browse files
committed
errors: split to codes.go
1 parent 3acf09e commit b1c0a3a

File tree

2 files changed

+82
-43
lines changed

2 files changed

+82
-43
lines changed

codes.go

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Copyright 2020 The Go Language Server Authors
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
package jsonrpc2
5+
6+
// Code is an int64 error code as defined in the JSON-RPC spec.
7+
type Code int64
8+
9+
// list of JSON-RPC error codes.
10+
const (
11+
// ParseError is the invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
12+
ParseError Code = -32700
13+
14+
// InvalidRequest is the JSON sent is not a valid Request object.
15+
InvalidRequest Code = -32600
16+
17+
// MethodNotFound is the method does not exist / is not available.
18+
MethodNotFound Code = -32601
19+
20+
// InvalidParams is the invalid method parameter(s).
21+
InvalidParams Code = -32602
22+
23+
// InternalError is the internal JSON-RPC error.
24+
InternalError Code = -32603
25+
26+
// ServerNotInitialized is the error of server not initialized.
27+
ServerNotInitialized Code = -32002
28+
29+
// UnknownError should be used for all non coded errors.
30+
UnknownError Code = -32001
31+
32+
// RequestCancelled is the cancellation error.
33+
//
34+
// Defined by the Language Server Protocol.
35+
RequestCancelled Code = -32800
36+
37+
// ContentModified is the state change that invalidates the result of a request in execution.
38+
//
39+
// Defined by the Language Server Protocol.
40+
ContentModified Code = -32801
41+
42+
// ServerOverloaded is returned when a message was refused due to a
43+
// server being temporarily unable to accept any new messages.
44+
ServerOverloaded Code = -32000
45+
46+
codeServerErrorStart Code = -32099
47+
codeServerErrorEnd Code = -32000
48+
)
49+
50+
// list of JSON-RPC errors.
51+
var (
52+
// ErrUnknown should be used for all non coded errors.
53+
ErrUnknown = Error{Code: UnknownError, Message: "JSON-RPC unknown error"}
54+
55+
// ErrParse is used when invalid JSON was received by the server.
56+
ErrParse = Error{Code: ParseError, Message: "JSON-RPC parse error"}
57+
58+
// ErrInvalidRequest is used when the JSON sent is not a valid Request object.
59+
ErrInvalidRequest = Error{Code: InvalidRequest, Message: "JSON-RPC invalid request"}
60+
61+
// ErrMethodNotFound should be returned by the handler when the method does
62+
// not exist / is not available.
63+
ErrMethodNotFound = Error{Code: MethodNotFound, Message: "JSON-RPC method not found"}
64+
65+
// ErrInvalidParams should be returned by the handler when method
66+
// parameter(s) were invalid.
67+
ErrInvalidParams = Error{Code: InvalidParams, Message: "JSON-RPC invalid params"}
68+
69+
// ErrInternal is not currently returned but defined for completeness.
70+
ErrInternal = Error{Code: InternalError, Message: "JSON-RPC internal error"}
71+
72+
// ErrServerOverloaded is returned when a message was refused due to a
73+
// server being temporarily unable to accept any new messages.
74+
ErrServerOverloaded = Error{Code: ServerOverloaded, Message: "JSON-RPC overloaded"}
75+
76+
// ErrIdleTimeout is returned when serving timed out waiting for new connections.
77+
ErrIdleTimeout = constErr("timed out waiting for new connections")
78+
)

errors.go

Lines changed: 4 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -10,49 +10,6 @@ import (
1010
"fmt"
1111
)
1212

13-
// Code represents a error's category.
14-
type Code int64
15-
16-
const (
17-
// ParseError is the invalid JSON was received by the server. An error occurred on the server while parsing the JSON text.
18-
ParseError Code = -32700
19-
20-
// InvalidRequest is the JSON sent is not a valid Request object.
21-
InvalidRequest Code = -32600
22-
23-
// MethodNotFound is the method does not exist / is not available.
24-
MethodNotFound Code = -32601
25-
26-
// InvalidParams is the invalid method parameter(s).
27-
InvalidParams Code = -32602
28-
29-
// InternalError is the internal JSON-RPC error.
30-
InternalError Code = -32603
31-
32-
// ServerNotInitialized is the error of server not initialized.
33-
ServerNotInitialized Code = -32002
34-
35-
// UnknownError should be used for all non coded errors.
36-
UnknownError Code = -32001
37-
38-
// RequestCancelled is the cancellation error.
39-
//
40-
// Defined by the Language Server Protocol.
41-
RequestCancelled Code = -32800
42-
43-
// ContentModified is the state change that invalidates the result of a request in execution.
44-
//
45-
// Defined by the Language Server Protocol.
46-
ContentModified Code = -32801
47-
48-
// ServerOverloaded is returned when a message was refused due to a
49-
// server being temporarily unable to accept any new messages.
50-
ServerOverloaded Code = -32000
51-
52-
codeServerErrorStart Code = -32099
53-
codeServerErrorEnd Code = -32000
54-
)
55-
5613
// Error represents a jsonrpc2 error.
5714
type Error struct {
5815
// Code a number indicating the error type that occurred.
@@ -99,3 +56,7 @@ func Errorf(c Code, format string, args ...interface{}) *Error {
9956

10057
return e
10158
}
59+
60+
type constErr string
61+
62+
func (e constErr) Error() string { return string(e) }

0 commit comments

Comments
 (0)