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
- 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.
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
- 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.
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
- Telegram bot token is not set
- Telegram chat ID is not set
- MeoW 昵称为空
- OneBot endpoint is not set
- OneBot requires either a user ID or group ID
AI-assisted analysis of babalae/better-genshin-impact@a7cb36712d (2026-08-13).
Data as JSON: /api/errors/c5b56db2221512d6.
Report an issue: GitHub.