microsoft/typescript-go · error · ErrorCode
-32602
-32602
Error message
%w: expected no params, got %s
What it means
Returned by lsproto.UnmarshalParams when a method whose params type is the marker NoParams (declared to take no parameters, e.g. shutdown or the workspace/*/refresh requests) arrives with a non-empty params payload. The base protocol lets params be optional, so this library enforces the declaration at dispatch time and wraps the error with ErrorCodeInvalidParams (-32602) so it maps to a standard JSON-RPC error response.
Source
Thrown at internal/lsp/lsproto/lsp.go:250
//
// A [NoParams] method must be given no params; every other method must be given
// params as an object or array. A violation returns [ErrorCodeInvalidParams].
func UnmarshalParams[T any](req *RequestMessage) (T, error) {
var params T
var raw json.Value
if req.Params != nil {
v, ok := req.Params.(json.Value)
if !ok {
return params, fmt.Errorf("%w: unexpected params type %T", ErrorCodeInvalidParams, req.Params)
}
raw = v
}
// params is the zero value of T; this asserts on its type, i.e. whether the
// method was declared with NoParams.
if _, declaresNoParams := any(params).(NoParams); declaresNoParams {
if len(raw) != 0 {
return params, fmt.Errorf("%w: expected no params, got %s", ErrorCodeInvalidParams, raw)
}
return params, nil
}
// The base protocol defines params as `array | object`; reject anything else
// (absent, null, or a scalar).
if k := raw.Kind(); k != '{' && k != '[' {
return params, fmt.Errorf("%w: params must be an object or array", ErrorCodeInvalidParams)
}
if err := json.Unmarshal(raw, ¶ms); err != nil {
return params, fmt.Errorf("%w: %w", ErrorCodeInvalidParams, err)
}
return params, nil
}
type Null struct{}
func (Null) UnmarshalJSONFrom(dec *json.Decoder) error {View on GitHub (pinned to 1bcfa18d79)
Solutions
- Omit the params member entirely from the JSON-RPC message for methods declared NoParams.
- If your client framework cannot omit params, special-case empty objects to drop the key before sending.
- When writing server handlers, only dispatch methods via UnmarshalParams[lsproto.NoParams] when the spec truly has no params; otherwise accept the empty object shape your client emits.
Example fix
// before
{"jsonrpc":"2.0","id":1,"method":"shutdown","params":{}}
// after
{"jsonrpc":"2.0","id":1,"method":"shutdown"} Defensive patterns
Strategy: validation
Validate before calling
// drop params entirely for parameterless methods before writing the frame
var noParamsMethods = map[string]bool{
"shutdown": true,
"workspace/semanticTokens/refresh": true,
"workspace/inlayHint/refresh": true,
"workspace/codeLens/refresh": true,
"workspace/diagnostic/refresh": true,
"exit": true,
}
func frame(method string, params any) map[string]any {
m := map[string]any{"jsonrpc": "2.0", "method": method}
if !noParamsMethods[method] {
m["params"] = params
}
return m
} Type guard
func isNoParamsMethod(method string) bool {
switch method {
case "shutdown", "exit", "workspace/semanticTokens/refresh", "workspace/inlayHint/refresh", "workspace/codeLens/refresh", "workspace/diagnostic/refresh":
return true
}
return false
} Try / catch
// server-side dispatcher: map -32602 'expected no params' to a clean response
if errors.Is(err, lsproto.ErrorCodeInvalidParams) && strings.Contains(err.Error(), "expected no params") {
return sendError(id, fmt.Errorf("%w: method takes no parameters", lsproto.ErrorCodeInvalidParams))
} Prevention
- Omit the params member for methods declared without parameters; do not send {} or null.
- Special-case empty params objects in generic client frameworks and strip them.
- Keep a list of NoParams methods beside your request-building code.
When it happens
Trigger: A client sends "params": {} or any params value with the shutdown request, or attaches params to a notification whose Go handler dispatches via UnmarshalParams[lsproto.NoParams]. Line 248-251 checks the type assertion any(params).(NoParams) and rejects any raw bytes with len != 0.
Common situations: Client frameworks that always inject an empty params object into every request; test harnesses templating requests with a fixed params key; middleware that rewrites absent params to {} or null; protocol libraries that cannot express parameterless methods.
Related errors
- expected null, got %s
- missing required properties: %s
- invalid %s: got %v
- invalid %s: %s
- expected %s value %s, got %s
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/395b8249d77fb60e.
Report an issue: GitHub.