coder/code-server · warning · HttpError

socketPath is required

Error message

socketPath is required

What it means

Thrown by the POST /delete-session route of the editor session manager socket server when req.body.socketPath is missing. It is an HttpError (400) routed through errorHandler. The route deletes a tracked editor session by its socket path, so the path is mandatory.

Source

Thrown at src/node/vscodeSocket.ts:68

      const socketPath = await editorSessionManager.getConnectedSocketPath(filePath)
      const response: GetSessionResponse = { socketPath }
      res.json(response)
    },
  )

  router.post<{}, string, AddSessionRequest | undefined>("/add-session", async (req, res) => {
    const entry = req.body?.entry
    if (!entry) {
      throw new HttpError("entry is required", HttpCode.BadRequest)
    }
    editorSessionManager.addSession(entry)
    res.status(200).send("session added")
  })

  router.post<{}, string, DeleteSessionRequest | undefined>("/delete-session", async (req, res) => {
    const socketPath = req.body?.socketPath
    if (!socketPath) {
      throw new HttpError("socketPath is required", HttpCode.BadRequest)
    }
    editorSessionManager.deleteSession(socketPath)
    res.status(200).send("session deleted")
  })

  router.use(errorHandler)

  const server = http.createServer(router)
  try {
    await listen(server, { socket: codeServerSocketPath })
  } catch (e) {
    logger.warn(`Could not create socket at ${codeServerSocketPath}`)
  }
  return server
}

export class EditorSessionManager {
  // Map from socket path to EditorSessionEntry.

View on GitHub (pinned to 51f90a376b)

Solutions

  1. POST { "socketPath": "<the-socket-path>" } with Content-Type: application/json.
  2. Ensure the client sends the field with the exact name 'socketPath'.
  3. Confirm express.json() parsed the body (valid JSON + correct Content-Type).
  4. Align the client with the DeleteSessionRequest interface.

Example fix

// before
req.write(JSON.stringify({ path: sock }))
// after
req.write(JSON.stringify({ socketPath: sock }))
Defensive patterns

Strategy: validation

Validate before calling

// Before POST /delete-session
if (!socketPath) throw new Error('socketPath is required')
await post('/delete-session', { socketPath })

Type guard

function isDeleteSessionRequest(b: unknown): b is { socketPath: string } {
  return typeof b === 'object' && b !== null && typeof (b as any).socketPath === 'string' && (b as any).socketPath.length > 0
}

Try / catch

try {
  await post('/delete-session', { socketPath })
} catch (e) {
  if (/socketPath is required/.test(e.message)) throw new Error('missing socketPath in payload')
}

Prevention

When it happens

Trigger: A POST /delete-session whose JSON body lacks the 'socketPath' field, has an empty body, or whose body was not parsed as JSON. The handler reads req.body?.socketPath and rejects falsy values.

Common situations: A cleanup hook posting an empty body on shutdown; a Content-Type that defeats express.json(); a client schema drift where the field was renamed (e.g. 'path' instead of 'socketPath').

Related errors


AI-assisted analysis of coder/code-server@51f90a376b (2026-08-12). Data as JSON: /api/errors/e861e56cd3061efc. Report an issue: GitHub.