babalae/better-genshin-impact · error · NotifierException

Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.

Error message

Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.Message}

What it means

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.

Source

Thrown at BetterGenshinImpact/Service/Notifier/TelegramNotifier.cs:97

        if (httpClient != null)
        {
            _httpClient = httpClient;
            _ownsHttpClient = false;
        }
        else
        {
            var handler = new HttpClientHandler();
            if (proxyEnabled && !string.IsNullOrEmpty(proxyUrl))
                try
                {
                    handler.Proxy = new WebProxy(proxyUrl);
                    handler.UseProxy = true;
                }
                catch (UriFormatException ex)
                {
                    // 抛出异常以通知调用者配置错误
                    throw new NotifierException($"Invalid Telegram proxy URL format: {proxyUrl}. Details: {ex.Message}");
                }

            _httpClient = new HttpClient(handler) { Timeout = TimeSpan.FromSeconds(30) };
            _ownsHttpClient = true;
        }

        TelegramApiBaseUrl = FormatApiBaseUrl(telegramApiBaseUrl);
    }

    public void Dispose()
    {
        if (_ownsHttpClient) _httpClient.Dispose();
    }

    public async Task SendAsync(BaseNotificationData content)
    {
        if (string.IsNullOrEmpty(TelegramBotToken)) throw new NotifierException("Telegram bot token is not set");
        if (string.IsNullOrEmpty(TelegramChatId)) throw new NotifierException("Telegram chat ID is not set");

View on GitHub (pinned to a7cb36712d)

Solutions

  1. Provide the proxy URL with an explicit scheme: http://host:port or https://host:port.
  2. Validate with Uri.TryCreate(proxyUrl, UriKind.Absolute, out _) BEFORE constructing the notifier and show a friendly error.
  3. Trim whitespace from the proxy setting on save.

Example fix

// before
handler.Proxy = new WebProxy(proxyUrl);
handler.UseProxy = true;

// after
if (!Uri.TryCreate(proxyUrl, UriKind.Absolute, out var proxyUri))
    throw new NotifierException($"Invalid Telegram proxy URL format: {proxyUrl}. Expected http(s)://host:port");
handler.Proxy = new WebProxy(proxyUri);
handler.UseProxy = true;
Defensive patterns

Strategy: validation

Validate before calling

if (proxyEnabled && !string.IsNullOrEmpty(proxyUrl)
    && !Uri.TryCreate(proxyUrl, UriKind.Absolute, out var u))
    throw new InvalidOperationException($"Proxy URL is malformed: {proxyUrl}");

Type guard

static bool IsValidProxyUrl(string url)
    => string.IsNullOrEmpty(url) || Uri.TryCreate(url, UriKind.Absolute, out var u)
       && (u.Scheme == Uri.UriSchemeHttp || u.Scheme == Uri.UriSchemeHttps);

Try / catch

try { var n = new TelegramNotifier(null, token, chatId, apiBase, proxyUrl, proxyEnabled); }
catch (NotifierException ex) when (ex.Message.Contains("proxy URL format"))
{ /* prompt user to fix proxy URL with scheme, no retry */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13). Data as JSON: /api/errors/c5b56db2221512d6. Report an issue: GitHub.