coder/code-server · warning · HttpError

filePath is required

Error message

filePath is required

What it means

Thrown by the GET /session route of the editor session manager socket server (src/node/vscodeSocket.ts) when req.query.filePath is missing. It is an HttpError with status 400 and is funneled through the registered errorHandler middleware so the client receives a structured HTTP 400 rather than a crash.

Source

Thrown at src/node/vscodeSocket.ts:48

interface GetSessionResponse {
  socketPath?: string
}

export async function makeEditorSessionManagerServer(
  codeServerSocketPath: string,
  editorSessionManager: EditorSessionManager,
): Promise<http.Server> {
  const router = express()

  router.use(express.json())

  router.get<{}, GetSessionResponse | string | unknown, undefined, { filePath?: string }>(
    "/session",
    async (req, res) => {
      const filePath = req.query.filePath
      if (!filePath) {
        throw new HttpError("filePath is required", HttpCode.BadRequest)
      }
      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

View on GitHub (pinned to 51f90a376b)

Solutions

  1. Always include the query parameter: GET /session?filePath=<encodeURIComponent(absolutePath)>.
  2. In EditorSessionManagerClient.getConnectedSocketPath, confirm the filePath argument is a non-empty string before the request.
  3. URL-encode the path to avoid characters being parsed out of the query string.
  4. Upgrade any custom client to match the current /session contract.

Example fix

// before
http.get({ path: '/session', socketPath })
// after
http.get({ path: '/session?filePath=' + encodeURIComponent(filePath), socketPath })
Defensive patterns

Strategy: validation

Validate before calling

// Before calling GET /session
function sessionPath(socketPath: string, filePath: string): string {
  if (!filePath) throw new Error('filePath is required')
  return '/session?filePath=' + encodeURIComponent(filePath)
}

Type guard

function hasFilePath(q: unknown): q is { filePath: string } {
  return typeof q === 'object' && q !== null && typeof (q as any).filePath === 'string' && (q as any).filePath.length > 0
}

Try / catch

try {
  const res = await get('/session?filePath=' + encodeURIComponent(filePath))
  if (res.statusCode === 400) throw new Error('filePath missing or invalid')
} catch (e) { /* handle */ }

Prevention

When it happens

Trigger: An HTTP GET to /session on the code-server socket without a ?filePath= query parameter, or with an empty value. The route's only purpose is to map a file path to a connected VS Code socket, so filePath is mandatory.

Common situations: A client (e.g. the EditorSessionManagerClient or a CLI integration) that forgot to append ?filePath=; a URL-encoding bug that strips the parameter; a stale client built against an older API that did not require filePath.

Related errors


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