DTK0011: RPC Function Error
Package:
@vitejs/devtools
Message
RPC error on executing "
{name}"
Cause
This error is logged when an individual RPC function throws during execution. It is triggered by the onFunctionError hook in the createRpcServer configuration inside createWsServer(). The {name} parameter identifies which RPC function failed.
When a client invokes a server-side RPC function and that function throws, the RPC layer catches the error, logs this diagnostic with the function name, and propagates the error back to the caller. The original error is attached as cause.
Example
A buggy RPC function that throws at runtime:
ts
import { defineRpcFunction } from '@vitejs/devtools-kit'
const myFunction = defineRpcFunction({
name: 'my-plugin:get-data',
async handler() {
// This throws and triggers DTK0011 with name "my-plugin:get-data"
throw new Error('Database connection failed')
},
})When a client calls rpc.invoke('my-plugin:get-data'), the server logs:
RPC error on executing "my-plugin:get-data"Fix
- Check the
causeattached to the diagnostic for the original error and stack trace. - Fix the underlying issue in your RPC function handler.
- Ensure your handler properly handles edge cases (missing data, invalid input, unavailable resources).
ts
const myFunction = defineRpcFunction({
name: 'my-plugin:get-data',
async handler() {
try {
return await fetchData()
}
catch (error) {
// Handle gracefully instead of letting it throw
return { error: 'Data unavailable' }
}
},
})Source
packages/core/src/node/ws.ts