{"record":{"id":"7e70ad0e3b46af20","repo":"farion1231/cc-switch","slug":"error","errorCode":null,"errorMessage":"${error}","messagePattern":"\\$\\{error\\}","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/lib/api/globalProxy.ts","lineNumber":55,"sourceCode":" *\n * @returns 代理 URL，null 表示未配置（直连）\n */\nexport async function getGlobalProxyUrl(): Promise<string | null> {\n  return invoke<string | null>(\"get_global_proxy_url\");\n}\n\n/**\n * 设置全局代理 URL\n *\n * @param url - 代理 URL（如 http://127.0.0.1:7890 或 socks5://127.0.0.1:1080）\n *              空字符串表示清除代理（直连）\n */\nexport async function setGlobalProxyUrl(url: string): Promise<void> {\n  try {\n    return await invoke(\"set_global_proxy_url\", { url });\n  } catch (error) {\n    // Tauri invoke 错误可能是字符串\n    throw new Error(typeof error === \"string\" ? error : String(error));\n  }\n}\n\n/**\n * 测试代理连接\n *\n * @param url - 要测试的代理 URL\n * @returns 测试结果，包含是否成功、延迟和错误信息\n */\nexport async function testProxyUrl(url: string): Promise<ProxyTestResult> {\n  return invoke<ProxyTestResult>(\"test_proxy_url\", { url });\n}\n\n/**\n * 获取当前出站代理状态\n *\n * @returns 代理状态，包含是否启用和代理 URL\n */","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/farion1231/cc-switch/blob/0b5da510168914b251481654a568c3ffacd62cf4/src/lib/api/globalProxy.ts#L37-L73","documentation":"setGlobalProxyUrl forwards the URL to the Tauri command set_global_proxy_url and re-wraps any rejection as an Error, normalizing the string payloads Tauri invoke produces (typeof error === 'string' ? error : String(error)). The message text therefore comes from the Rust backend, not from this file — typical causes are a malformed/unsupported proxy URL or an OS-level failure while applying the system proxy.","triggerScenarios":"invoke('set_global_proxy_url', { url }) rejects — e.g. url '127.0.0.1:7890' without a scheme, an unsupported scheme, a URL the backend cannot parse, or the OS refusing the proxy change.","commonSituations":"User pastes host:port without an http:// or socks5:// prefix; proxy credentials/port typed into the URL field; security software or permissions blocking system proxy changes.","solutions":["Normalize input to a full URL with scheme (http://127.0.0.1:7890 or socks5://127.0.0.1:1080) before calling","Pre-validate with new URL(url) plus a scheme allow-list in the UI; use testProxyUrl to confirm reachability first","Inspect the Rust set_global_proxy_url command's error strings and map them to actionable UI messages"],"exampleFix":"// before\nawait setGlobalProxyUrl('127.0.0.1:7890'); // scheme-less URL rejected by backend\n\n// after\nconst u = new URL('http://127.0.0.1:7890'); // build with explicit scheme\nawait setGlobalProxyUrl(u.toString());","handlingStrategy":"try-catch","validationCode":"function normalizeProxyUrl(input: string): string | null {\n  try {\n    const u = new URL(input.trim());\n    return ['http:', 'https:', 'socks5:'].includes(u.protocol) ? u.toString() : null;\n  } catch {\n    return null;\n  }\n}\nconst normalized = normalizeProxyUrl(raw);\nif (!normalized) {\n  // show a field error; do not call setGlobalProxyUrl\n}","typeGuard":null,"tryCatchPattern":"try {\n  await setGlobalProxyUrl(url);\n} catch (error) {\n  // message is the backend string normalized to Error by the wrapper\n  showProxyError(error instanceof Error ? error.message : String(error));\n}","preventionTips":["Always include the scheme in proxy URLs","Confirm reachability with testProxyUrl before applying","Keep a map of known backend error strings to actionable UI hints"],"tags":["tauri","proxy","invoke","validation"],"backgroundTag":"invalid-proxy-url","analyzedSha":"0b5da510168914b251481654a568c3ffacd62cf4","analyzedAt":"2026-08-20T14:29:00.113Z","contentChangedAt":"2026-08-20T14:29:00.113Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}