hcengineering/platform · error
Missing document id
Error message
Missing document id
What it means
The /rpc/:id route requires the :id path parameter to identify the target document. When the id is missing or an empty string, the server responds HTTP 400 with {error:'Missing document id'}.
Source
Thrown at server/collaborator/src/server.ts:171
res.status(401).send({ error: 'Unauthorized' })
return
}
const rawToken = authHeader.split(' ')[1]
let token: Token
try {
token = decodeToken(rawToken)
} catch {
res.status(401).send({ error: 'Unauthorized' })
return
}
const documentId = req.params.id
if (documentId === undefined || documentId === '') {
const response: RpcErrorResponse = {
error: 'Missing document id'
}
res.status(400).send(response)
return
}
const request = req.body as RpcRequest
const method = methods[request.method]
if (method === undefined) {
const response: RpcErrorResponse = {
error: 'Unknown method'
}
res.status(400).send(response)
return
}
const context = await getContext(rawToken, token)
rpcCtx.info('rpc', { method: request.method, connectionId: context.connectionId, mode: token.extra?.mode ?? '' })
await rpcCtx.with(View on GitHub (pinned to 63e28dc964)
Solutions
- Include the document/tx id in the URL path: POST /rpc/<documentId>.
- Validate the document id is a non-empty string before building the request URL.
- Fix string interpolation that yields an empty id (e.g. undefined template variable).
Example fix
// before
const url = `/rpc/${docId ?? ''}`
// after
if (!docId) throw new Error('documentId is required')
const url = `/rpc/${docId}` Defensive patterns
Strategy: validation
Validate before calling
function buildRpcUrl(base: string, documentId: string | undefined): string {
if (typeof documentId !== 'string' || documentId === '') throw new Error('documentId is required')
return `${base}/rpc/${documentId}`
} Type guard
function hasDocumentId(id: unknown): id is string {
return typeof id === 'string' && id.length > 0
} Try / catch
try {
const url = buildRpcUrl(base, docId)
return await postRpc(url, body)
} catch (e) {
if (e instanceof MissingDocumentIdError) {
console.error('Cannot call RPC without a document id'); return null
}
throw e
} Prevention
- Validate document ids at the point where RPC URLs are constructed.
- Use typed wrappers around RPC calls instead of raw string interpolation.
- Check for undefined variables before template interpolation in URL builders.
When it happens
Trigger: POST to /rpc/ (trailing empty id) or /rpc with the document id omitted from the URL path.
Common situations: URL template interpolation with an undefined/empty document id; route builders dropping the id; clients hardcoding '/rpc/' without substituting the id.
Related errors
- Unknown method
- Failed to load server config
- getDisplayMedia not supported
- No screen access granted
- platform.status.BadRequest
AI-assisted analysis of hcengineering/platform@63e28dc964 (2026-08-29).
Data as JSON: /api/errors/246fe85b441631a9.
Report an issue: GitHub.