{"record":{"id":"4208829e016b26d8","repo":"BabylonJS/Babylon.js","slug":"session-id-must-be-a-number","errorCode":null,"errorMessage":"Session id must be a number.","messagePattern":"Session id must be a number\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/dev/inspector-v2/src/cli/cli.ts","lineNumber":242,"sourceCode":"async function WithBridge(bridgeScript: string | undefined, fn: (socket: WebSocket) => Promise<void>): Promise<void> {\r\n    const socket = await EnsureBridge(Config.cliPort, bridgeScript);\r\n    try {\r\n        await fn(socket);\r\n    } finally {\r\n        socket.close();\r\n    }\r\n}\r\n\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","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/BabylonJS/Babylon.js/blob/0592b347b8a4ee0236089ea86a749cacfdb266d8/packages/dev/inspector-v2/src/cli/cli.ts#L224-L260","documentation":"ValidateSessionId parses the --session CLI value as a base-10 integer and throws when it is not numeric, before looking the session up in the bridge's session list.","triggerScenarios":"Passing --session with a non-numeric value (e.g. --session abc, --session \"1,2\", or an empty string) to a CLI command that resolves a target inspector session.","commonSituations":"Copy-pasting a session name instead of its numeric id; shell mangling the argument; scripting with a placeholder that was never substituted; confusing session name with session id.","solutions":["Pass the numeric session id: --session 1 instead of a name or non-numeric string.","Run the sessions-listing command (or --session without value flow) to discover valid numeric ids.","Sanitize shell scripts: ensure the variable interpolated into --session is a number (e.g. ${SESSION_ID:?})."],"exampleFix":"// before\ncli inspect --session \"my-session\" // throws\n// after\ncli sessions        // list ids\ncli inspect --session 2","handlingStrategy":"validation","validationCode":"function isValidSessionIdArg(v: string | undefined): boolean {\n  return v !== undefined && /^\\d+$/.test(v);\n}\nif (!isValidSessionIdArg(explicitId)) throw new Error(\"--session must be a numeric id\");","typeGuard":"function isNumericId(v: string | undefined): v is string {\n  return typeof v === \"string\" && /^\\d+$/.test(v);\n}","tryCatchPattern":"try {\n  const session = ValidateSessionId(raw, sessions);\n} catch (e) {\n  if (e instanceof Error && e.message === \"Session id must be a number.\") {\n    console.error(`--session must be numeric, got \"${raw}\". Run 'sessions' to list ids.`);\n  } else throw e;\n}","preventionTips":["Validate --session with /^\\d+$/ before invoking the CLI API","Distinguish session ids (numbers) from session names in scripts and docs","Quote shell variables and fail fast when the id variable is unset"],"tags":["cli","validation","arguments"],"backgroundTag":"invalid-argument-format","analyzedSha":"0592b347b8a4ee0236089ea86a749cacfdb266d8","analyzedAt":"2026-08-30T15:11:20.442Z","schemaVersion":2},"datasetVersion":"2026-08-30T18:17:15.746Z"}