{"record":{"id":"d16fa1767ab041d8","repo":"BabylonJS/Babylon.js","slug":"session-parsed-does-not-exist-active-sessions","errorCode":null,"errorMessage":"Session ${parsed} does not exist. Active sessions:\n${list}","messagePattern":"Session (.+?) does not exist\\. Active sessions:\n(.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/cli/cli.ts","lineNumber":250,"sourceCode":"\r\n/**\r\n * Parses and validates an explicit session id string against the list of active sessions.\r\n * @param explicitId The session id string to validate.\r\n * @param sessions The list of active sessions from the bridge.\r\n * @returns The matching session info.\r\n */\r\nexport function ValidateSessionId(explicitId: string, sessions: SessionInfo[]): SessionInfo {\r\n    const parsed = parseInt(explicitId, 10);\r\n    if (isNaN(parsed)) {\r\n        throw new Error(\"Session id must be a number.\");\r\n    }\r\n    const match = sessions.find((s) => s.id === parsed);\r\n    if (!match) {\r\n        if (sessions.length === 0) {\r\n            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","sourceCodeStart":232,"sourceCodeEnd":268,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/cli/cli.ts#L232-L268","documentation":"ValidateSessionId throws this variant when the numeric id does not match any active session, and at least one other session exists. The message enumerates the available ids/names so the caller can pick a valid one.","triggerScenarios":"Passing --session <n> with an id that is stale (page reloaded, bridge restarted and ids reassigned) or simply wrong while other sessions are live.","commonSituations":"Reusing a session id from an earlier run in a script; multiple tabs open and targeting the wrong id; ids shifted after some sessions disconnected.","solutions":["Use the id list printed in the error (or run the sessions command) and pass one of the currently listed ids.","Re-fetch session ids each run instead of hardcoding them in scripts.","If multiple tabs are open, target the correct one by matching s.name against the listed session names."],"exampleFix":"// before\ncli inspect --session 7   # stale id\n// after\n# error lists: [1] TabA, [2] TabB\ncli inspect --session 2","handlingStrategy":"validation","validationCode":"function sessionExists(sessions: SessionInfo[], id: number): boolean {\n  return sessions.some((s) => s.id === id);\n}\nif (!sessionExists(sessions, parsed)) {\n  console.error(`Unknown id ${parsed}. Available: ${sessions.map((s) => s.id).join(\", \")}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  const s = ValidateSessionId(id, sessions);\n} catch (e) {\n  if (e instanceof Error && e.message.includes(\"does not exist. Active sessions:\")) {\n    console.error(e.message); // shows valid ids to pick from\n  } else throw e;\n}","preventionTips":["Fetch fresh ids each run; never hardcode session ids in scripts","Match sessions by name when multiple tabs are open","Re-resolve ids after any page reload or bridge restart"],"tags":["cli","session","validation"],"backgroundTag":"no-active-session","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}