MCPcopy
hub / github.com/nuxt/nuxt / sendError

Function sendError

packages/vite/src/plugins/vite-node.ts:585–611  ·  view source on GitHub ↗
(socket: net.Socket, id: number, error: any)

Source from the content-addressed store, hash-verified

583}
584
585function sendError (socket: net.Socket, id: number, error: any) {
586 const errorResponse = {
587 id,
588 type: 'error',
589 error: {
590 message: error.message,
591 stack: error.stack,
592 status: error.status,
593 statusText: error.statusText,
594 data: error.data,
595 },
596 }
597 const responseJSON = JSON.stringify(errorResponse)
598 const messageBuffer = Buffer.from(responseJSON, 'utf-8')
599 const messageLength = messageBuffer.length
600
601 // Pre-allocate single buffer for length + message to avoid Buffer.concat()
602 const fullMessage = Buffer.alloc(4 + messageLength)
603 fullMessage.writeUInt32BE(messageLength, 0)
604 messageBuffer.copy(fullMessage, 4)
605
606 socket.write(fullMessage, (err) => {
607 if (err) {
608 // Failed to send error response - connection likely closed
609 }
610 })
611}
612
613export type ViteNodeServerOptions = {
614 baseURL: string

Callers 3

processMessageFunction · 0.85
sendResponseFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…