{"record":{"id":"70cca9aadc1309ca","repo":"Kuberwastaken/claurst","slug":"failed-to-open-browser-for-oauth","errorCode":null,"errorMessage":"Failed to open browser for OAuth: {}","messagePattern":"Failed to open browser for OAuth: (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src-rust/crates/mcp/src/oauth.rs","lineNumber":305,"sourceCode":"            .query_pairs()\n            .find(|(key, _)| key == \"state\")\n            .map(|(_, value)| value.to_string());\n        if received_state.as_deref() != Some(expected_state) {\n            anyhow::bail!(\"OAuth state mismatch — possible CSRF attack\");\n        }\n    }\n\n    parsed_url\n        .query_pairs()\n        .find(|(key, _)| key == \"code\")\n        .map(|(_, value)| value.to_string())\n        .ok_or_else(|| anyhow::anyhow!(\"OAuth callback did not contain an authorization code\"))\n}\n\npub async fn run_mcp_auth_session(session: McpAuthSession) -> anyhow::Result<McpAuthResult> {\n    let (listener, host, callback_path) = bind_callback_listener(&session.redirect_uri).await?;\n    open::that(&session.auth_url)\n        .map_err(|e| anyhow::anyhow!(\"Failed to open browser for OAuth: {}\", e))?;\n\n    let code = wait_for_authorization_code(listener, &host, &callback_path, None).await?;\n    let mut token = exchange_code(\n        &session.metadata.token_endpoint,\n        &code,\n        &session.verifier,\n        &session.redirect_uri,\n    )\n    .await?;\n    token.server_name = session.server_name.clone();\n    store_mcp_token(&token).map_err(|e| {\n        anyhow::anyhow!(\n            \"Failed to store MCP token for '{}': {}\",\n            session.server_name,\n            e\n        )\n    })?;\n","sourceCodeStart":287,"sourceCodeEnd":323,"githubUrl":"https://github.com/Kuberwastaken/claurst/blob/b0637c97ec34144387cbf2f74f65df6d16a6cef1/src-rust/crates/mcp/src/oauth.rs#L287-L323","documentation":"The `open` crate failed to launch the system browser (or URL handler) for the MCP OAuth authorization URL. The auth session had already bound its callback listener; the failure is environment-level — no default browser configured, headless/session environment without a URL opener, or the OS handler returned an error.","triggerScenarios":"Thrown at src-rust/crates/mcp/src/oauth.rs:305 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set BROWSER / default browser environment variables and retry","Copy the authorization URL from logs and open it manually in a browser within the 180s callback timeout","On headless systems, run the auth flow from a machine with a desktop session"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"b0637c97ec34144387cbf2f74f65df6d16a6cef1","analyzedAt":"2026-09-10T00:24:58.650Z","contentChangedAt":"2026-09-10T00:24:58.650Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}