Summary
ResponseError (src/Protocol/ResponseError.php) hardcodes each JSON-RPC / LSP
error code as a magic integer inside a static factory (parseError -> -32700,
invalidRequest -> -32600, serverNotInitialized -> -32002, etc.). These codes
are a fixed, spec-defined set (JSON-RPC 2.0 + LSP 3.17), which is exactly what an
int-backed enum models: it names the numbers in one place and removes the inline
literals.
Proposed change
Introduce something like:
enum ErrorCode: int
{
case ParseError = -32700;
case InvalidRequest = -32600;
case MethodNotFound = -32601;
case InvalidParams = -32602;
case InternalError = -32603;
case ServerNotInitialized = -32002;
}
and have ResponseError carry it (adjusting jsonSerialize() to emit
$this->code->value).
Design decision to make
JSON-RPC reserves -32000..-32099 for server-defined codes and LSP permits custom
ones, so a pure enum cannot represent an arbitrary future code. Every code the
server emits today is standard, so an enum is sufficient now, but decide whether
ResponseError::$code becomes strictly the enum or ErrorCode|int before
committing to the shape.
Scope note
This is a refactor of a pre-existing pattern, deferred out of slice S1.4 (which
only added serverNotInitialized consistent with the existing factories) to keep
that slice's diff focused.
This issue was written by AI (reviewed by a human).
Summary
ResponseError(src/Protocol/ResponseError.php) hardcodes each JSON-RPC / LSPerror code as a magic integer inside a static factory (
parseError-> -32700,invalidRequest-> -32600,serverNotInitialized-> -32002, etc.). These codesare a fixed, spec-defined set (JSON-RPC 2.0 + LSP 3.17), which is exactly what an
int-backed enum models: it names the numbers in one place and removes the inline
literals.
Proposed change
Introduce something like:
and have
ResponseErrorcarry it (adjustingjsonSerialize()to emit$this->code->value).Design decision to make
JSON-RPC reserves -32000..-32099 for server-defined codes and LSP permits custom
ones, so a pure enum cannot represent an arbitrary future code. Every code the
server emits today is standard, so an enum is sufficient now, but decide whether
ResponseError::$codebecomes strictly the enum orErrorCode|intbeforecommitting to the shape.
Scope note
This is a refactor of a pre-existing pattern, deferred out of slice S1.4 (which
only added
serverNotInitializedconsistent with the existing factories) to keepthat slice's diff focused.
This issue was written by AI (reviewed by a human).