Skip to content

Commit

Permalink
fix: rpc timeout error messages to log caller
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Feb 2, 2024
1 parent 1fa90d1 commit 8e16d65
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 11 deletions.
2 changes: 1 addition & 1 deletion packages/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
"@vitest/ws-client": "workspace:*",
"@vueuse/core": "^10.6.1",
"ansi-to-html": "^0.7.2",
"birpc": "0.2.14",
"birpc": "0.2.15",
"codemirror": "^5.65.16",
"codemirror-theme-vars": "^0.1.2",
"cypress": "^13.6.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/vitest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
"@types/node": "^20.11.5",
"@types/prompts": "^2.4.9",
"@types/sinonjs__fake-timers": "^8.1.5",
"birpc": "0.2.14",
"birpc": "0.2.15",
"chai-subset": "^1.6.0",
"cli-truncate": "^4.0.0",
"expect-type": "^0.17.3",
Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/api/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export function setup(vitestOrWorkspace: Vitest | WorkspaceProject, _server?: Vi
eventNames: ['onUserConsoleLog', 'onFinished', 'onCollected', 'onCancel'],
serialize: (data: any) => stringify(data, stringifyReplace),
deserialize: parse,
onTimeoutError(functionName) {
throw new Error(`[vitest-api]: Timeout calling "${functionName}"`)
},
},
)

Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/pools/forks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ function createChildProcessChannel(project: WorkspaceProject) {
on(fn) {
emitter.on(events.response, fn)
},
onTimeoutError(functionName) {
throw new Error(`[vitest-pool]: Timeout calling "${functionName}"`)
},
},
)

Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/pools/threads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ function createWorkerChannel(project: WorkspaceProject) {
on(fn) {
port.on('message', fn)
},
onTimeoutError(functionName) {
throw new Error(`[vitest-pool]: Timeout calling "${functionName}"`)
},
},
)

Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/pools/vmForks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ function createChildProcessChannel(project: WorkspaceProject) {
on(fn) {
emitter.on(events.response, fn)
},
onTimeoutError(functionName) {
throw new Error(`[vitest-pool]: Timeout calling "${functionName}"`)
},
},
)

Expand Down
3 changes: 3 additions & 0 deletions packages/vitest/src/node/pools/vmThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ function createWorkerChannel(project: WorkspaceProject) {
on(fn) {
port.on('message', fn)
},
onTimeoutError(functionName) {
throw new Error(`[vitest-pool]: Timeout calling "${functionName}"`)
},
},
)

Expand Down
8 changes: 8 additions & 0 deletions packages/vitest/src/runtime/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,14 @@ export function createRuntimeRpc(options: Pick<BirpcOptions<RuntimeRPC>, 'on' |
},
{
eventNames: ['onUserConsoleLog', 'onFinished', 'onCollected', 'onCancel'],
onTimeoutError(functionName, args) {
let message = `[vitest-worker]: Timeout calling "${functionName}"`

if (functionName === 'fetch' || functionName === 'transform' || functionName === 'resolveId')
message += ` with "${JSON.stringify(args)}"`

throw new Error(message)
},
...options,
},
))
Expand Down
2 changes: 1 addition & 1 deletion packages/ws-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"typecheck": "tsc --noEmit"
},
"dependencies": {
"birpc": "0.2.14",
"birpc": "0.2.15",
"flatted": "^3.2.9",
"ws": "^8.14.2"
},
Expand Down
3 changes: 3 additions & 0 deletions packages/ws-client/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ export function createClient(url: string, options: VitestClientOptions = {}) {
on: fn => (onMessage = fn),
serialize: stringify,
deserialize: parse,
onTimeoutError(functionName) {
throw new Error(`[vitest-ws-client]: Timeout calling "${functionName}"`)
},
}

ctx.rpc = createBirpc<WebSocketHandlers, WebSocketEvents>(
Expand Down
16 changes: 8 additions & 8 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e16d65

Please sign in to comment.