{"record":{"id":"c5b56db2221512d6","repo":"babalae/better-genshin-impact","slug":"invalid-telegram-proxy-url-format-proxyurl-det","errorCode":null,"errorMessage":"Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.Message}","messagePattern":"Invalid Telegram proxy URL format: (.+?)\\. Details: (.+?)","errorType":"exception","errorClass":"NotifierException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs","lineNumber":97,"sourceCode":"\n        if (httpClient != null)\n        {\n            _httpClient = httpClient;\n            _ownsHttpClient = false;\n        }\n        else\n        {\n            var handler = new HttpClientHandler();\n            if (proxyEnabled && !string.IsNullOrEmpty(proxyUrl))\n                try\n                {\n                    handler.Proxy = new WebProxy(proxyUrl);\n                    handler.UseProxy = true;\n                }\n                catch (UriFormatException ex)\n                {\n                    // 抛出异常以通知调用者配置错误\n                    throw new NotifierException($\"Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.Message}\");\n                }\n\n            _httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };\n            _ownsHttpClient = true;\n        }\n\n        TelegramApiBaseUrl = FormatApiBaseUrl(telegramApiBaseUrl);\n    }\n\n    public void Dispose()\n    {\n        if (_ownsHttpClient) _httpClient.Dispose();\n    }\n\n    public async Task SendAsync(BaseNotificationData content)\n    {\n        if (string.IsNullOrEmpty(TelegramBotToken)) throw new NotifierException(\"Telegram bot token is not set\");\n        if (string.IsNullOrEmpty(TelegramChatId)) throw new NotifierException(\"Telegram chat ID is not set\");","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs#L79-L115","documentation":"Thrown from the TelegramNotifier constructor when WebProxy(proxyUrl) raises UriFormatException, i.e. the proxy URL string cannot be parsed as a well-formed URI. Throwing in the ctor means the notifier cannot even be instantiated with a bad proxy.","triggerScenarios":"proxyEnabled is true, proxyUrl is non-empty, and new WebProxy(proxyUrl) throws UriFormatException. Note: only UriFormatException is caught here — other malformed-input exceptions (e.g. from a relative URI used as an absolute proxy) would escape uncaught.","commonSituations":"User typed a proxy without scheme (e.g. 127.0.0.1:7890 instead of http://127.0.0.1:7890); stray spaces; copy-paste artifacts; SOCKS URL on a host without socks support configured.","solutions":["Provide the proxy URL with an explicit scheme: http://host:port or https://host:port.","Validate with Uri.TryCreate(proxyUrl, UriKind.Absolute, out _) BEFORE constructing the notifier and show a friendly error.","Trim whitespace from the proxy setting on save."],"exampleFix":"// before\nhandler.Proxy = new WebProxy(proxyUrl);\nhandler.UseProxy = true;\n\n// after\nif (!Uri.TryCreate(proxyUrl, UriKind.Absolute, out var proxyUri))\n    throw new NotifierException($\"Invalid Telegram proxy URL format: {proxyUrl}. Expected http(s)://host:port\");\nhandler.Proxy = new WebProxy(proxyUri);\nhandler.UseProxy = true;","handlingStrategy":"validation","validationCode":"if (proxyEnabled && !string.IsNullOrEmpty(proxyUrl)\n    && !Uri.TryCreate(proxyUrl, UriKind.Absolute, out var u))\n    throw new InvalidOperationException($\"Proxy URL is malformed: {proxyUrl}\");","typeGuard":"static bool IsValidProxyUrl(string url)\n    => string.IsNullOrEmpty(url) || Uri.TryCreate(url, UriKind.Absolute, out var u)\n       && (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);","tryCatchPattern":"try { var n = new TelegramNotifier(null, token, chatId, apiBase, proxyUrl, proxyEnabled); }\ncatch (NotifierException ex) when (ex.Message.Contains(\"proxy URL format\"))\n{ /* prompt user to fix proxy URL with scheme, no retry */ }","preventionTips":["Always include the scheme (http:// or https://) in the proxy URL.","Trim whitespace and validate with Uri.TryCreate before construction.","For SOCKS proxies, ensure the platform supports them."],"tags":["telegram","proxy","config","validation","notifier"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}