microsoft/typescript-go · error
ErrInvalidRequest
ErrInvalidRequest
Error message
api: invalid request
What it means
Sentinel error marking caller-side malformed input. It is wrapped by the msgpack framing checks in protocol_msgpack.go (bad tuple marker, bad type marker, unknown type, bad binary marker) and by request validation failures in session.go. errors.Is(err, api.ErrInvalidRequest) distinguishes 'the client sent garbage' from server-side failures; the wrapped text carries specifics.
Source
Thrown at internal/api/proto.go:24
"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/checker"
"github.com/microsoft/typescript-go/internal/collections"
"github.com/microsoft/typescript-go/internal/core"
"github.com/microsoft/typescript-go/internal/diagnostics"
"github.com/microsoft/typescript-go/internal/jsnum"
"github.com/microsoft/typescript-go/internal/json"
"github.com/microsoft/typescript-go/internal/locale"
"github.com/microsoft/typescript-go/internal/ls/lsconv"
"github.com/microsoft/typescript-go/internal/lsp/lsproto"
"github.com/microsoft/typescript-go/internal/packagejson"
"github.com/microsoft/typescript-go/internal/project"
"github.com/microsoft/typescript-go/internal/tsoptions"
"github.com/microsoft/typescript-go/internal/tspath"
)
var (
ErrInvalidRequest = errors.New("api: invalid request")
ErrClientError = errors.New("api: client error")
)
type Method string
type (
SnapshotID uint64
ProjectID string
SymbolID uint64
TypeID uint32
SignatureID uint64
NodeHandle string
)
func ProjectHandle(p *project.Project) ProjectID {
return ProjectID(p.ID())
}
View on GitHub (pinned to 1bcfa18d79)
Solutions
- Read the text after the sentinel for the precise framing or validation cause
- Ensure both endpoints construct the matching Protocol implementation over the transport
- Fix the offending payload per the method's documented params type
- When writing a client in another language, mirror the frame format exactly: 0x93, type byte, bin8/16/32 method, bin8/16/32 payload
Example fix
// before proto := api.NewMessagePackProtocol(jsonRpcConn) // wrong framing // after proto := api.NewMessagePackProtocol(msgpackConn) // both ends msgpack tuples
Defensive patterns
Strategy: try-catch
Type guard
func isInvalidRequest(err error) bool { return errors.Is(err, api.ErrInvalidRequest) } Try / catch
err := conn.Run(ctx)
if err != nil && errors.Is(err, api.ErrInvalidRequest) {
// client sent malformed framing; message text after the sentinel says what
log.Printf("malformed client input: %v", err)
return nil // drop the connection quietly
} Prevention
- Use the same Protocol implementation on both ends of the transport
- Mirror the tuple format exactly in non-Go clients
- Test framing with golden byte fixtures
When it happens
Trigger: A msgpack stream whose tuple/type/bin marker bytes are wrong (desync or wrong wire format); a request whose params fail server-side validation and get wrapped at dispatch.
Common situations: Speaking plain JSON-RPC or LSP Content-Length framing into a MessagePackProtocol connection; a non-Go client with a buggy tuple encoder; payloads not matching the method schema.
Related errors
- %w: expected fixed 3-element array (0x93), received: 0x%02x
- %w: expected positive fixint or uint8 marker, received: 0x%0
- data too short for header: %d bytes
- ErrClientError
- DocumentIdentifier: expected string or object, got %v
AI-assisted analysis of microsoft/typescript-go@1bcfa18d79 (2026-08-16).
Data as JSON: /api/errors/bc6fb01fc368220c.
Report an issue: GitHub.