{"record":{"id":"b39635d1441ffe5b","repo":"BabylonJS/Babylon.js","slug":"a-session-id-is-required-use-session-to-list-ac","errorCode":null,"errorMessage":"A session id is required. Use --session to list active sessions, then pass --session <id>.","messagePattern":"A session id is required\\. Use --session to list active sessions, then pass --session <id>\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/cli/cli.ts","lineNumber":265,"sourceCode":"            throw new Error(`Session ${parsed} does not exist. No active sessions.`);\r\n        }\r\n        const list = sessions.map((s) => `  [${s.id}] ${s.name}`).join(\"\\n\");\r\n        throw new Error(`Session ${parsed} does not exist. Active sessions:\\n${list}`);\r\n    }\r\n    return match;\r\n}\r\n\r\n/**\r\n * Resolves and validates the session id. Requires an explicit session id\r\n * provided via `--session <id>`. Throws if the id is missing, non-numeric,\r\n * or does not match an active session.\r\n * @param socket The WebSocket connection to the bridge.\r\n * @param explicitId The session id string from --session.\r\n * @returns The validated numeric session id.\r\n */\r\nexport async function ResolveSessionId(socket: WebSocket, explicitId: string | undefined): Promise<number> {\r\n    if (explicitId === undefined) {\r\n        throw new Error(\"A session id is required. Use --session to list active sessions, then pass --session <id>.\");\r\n    }\r\n\r\n    const response = await SendAndReceive<SessionsResponse>(socket, { type: \"sessions\" });\r\n    return ValidateSessionId(explicitId, response.sessions).id;\r\n}\r\n\r\n/**\r\n * Parses command arguments from the rest array (everything after the command id).\r\n * @param rest The remaining CLI tokens after the command id.\r\n * @param globalHelp Whether --help was specified at the top level.\r\n * @returns The parsed command arguments and whether help was requested.\r\n */\r\nexport function ParseCommandArgs(rest: string[], globalHelp: boolean): { args: Record<string, string>; wantsHelp: boolean } {\r\n    const args: Record<string, string> = {};\r\n    let wantsHelp = globalHelp;\r\n    for (let i = 1; i < rest.length; i++) {\r\n        const token = rest[i];\r\n        if (token === \"--help\") {\r","sourceCodeStart":247,"sourceCodeEnd":283,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/cli/cli.ts#L247-L283","documentation":"ResolveSessionId requires an explicit --session value; when it is undefined it throws with instructions to list sessions and pass an id. It never guesses a default session.","triggerScenarios":"Running a CLI command that needs a target session without the --session flag, e.g. omitting it in an interactive run or a script where the argument was dropped.","commonSituations":"Forgetting the flag when multiple sessions exist; shell script variable empty so --session is omitted entirely; following outdated docs that predate the --session requirement.","solutions":["Add --session <id> to the command; run the sessions-listing command first to obtain the id.","In scripts, fail fast when the session variable is empty rather than silently omitting the flag.","If only one session is typically active, capture its id automatically from the sessions response and pass it explicitly."],"exampleFix":"// before\ncli inspect               # missing --session\n// after\nID=$(cli sessions --first-id)\ncli inspect --session \"$ID\"","handlingStrategy":"validation","validationCode":"function requireSessionFlag(v: string | undefined): string {\n  if (v === undefined || v === \"\") {\n    throw new Error(\"--session is required. Run 'sessions' to list ids, then pass --session <id>.\");\n  }\n  return v;\n}","typeGuard":"function hasSessionId(v: string | undefined): v is string {\n  return typeof v === \"string\" && v.length > 0;\n}","tryCatchPattern":"try {\n  const id = await ResolveSessionId(socket, explicitId);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"A session id is required\")) {\n    const sessions = await SendAndReceive<SessionsResponse>(socket, { type: \"sessions\" });\n    console.error(`--session required. Active sessions:\\n${sessions.sessions.map((s) => `  [${s.id}] ${s.name}`).join(\"\\n\")}`);\n  } else throw e;\n}","preventionTips":["Always pass --session in scripts; validate the variable is non-empty before invoking","Implement auto-discovery: if only one session is active, still fetch and pass its id explicitly","Update CLI usage/docs so invocations include --session"],"tags":["cli","arguments","session"],"backgroundTag":"missing-required-argument","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}