egametang/ET · error
http request fail: {link.Substring(0,link.IndexOf('?'))}\n{e
Error message
http request fail: {link.Substring(0,link.IndexOf('?'))}\n{e} What it means
Thrown by CoroutineHelper.HttpGet when UnityWebRequest.SendWebRequest() raises (network error, HTTP failure, timeout). The catch wraps the original exception. WARNING: the catch message itself calls link.Substring(0, link.IndexOf('?')) — if the link contains NO '?', IndexOf returns -1 and Substring(0,-1) throws ArgumentOutOfRangeException, masking the real network error with a string-processing crash. If the link has no query string, the error handler itself fails.
Source
Thrown at Packages/cn.etetet.loader/Scripts/Loader/Client/CoroutineHelper.cs:27
// 有了这个方法,就可以直接await Unity的AsyncOperation了
public static async ETTask GetAwaiter(this AsyncOperation asyncOperation)
{
ETTask task = ETTask.Create(true);
asyncOperation.completed += _ => { task.SetResult(); };
await task;
}
public static async ETTask<string> HttpGet(string link)
{
try
{
UnityWebRequest req = UnityWebRequest.Get(link);
await req.SendWebRequest();
return req.downloadHandler.text;
}
catch (Exception e)
{
throw new Exception($"http request fail: {link.Substring(0,link.IndexOf('?'))}\n{e}");
}
}
}
}View on GitHub (pinned to 5cab01f7a8)
Solutions
- Fix the latent bug: guard the IndexOf result before Substring (use link.IndexOf('?') >= 0 ? link.Substring(0, link.IndexOf('?')) : link).
- Validate the URL scheme/host before calling HttpGet and surface a clear error if unreachable.
- Wrap the HttpGet call in a retry/timeout policy so transient network failures don't crash client startup.
Example fix
// before
throw new Exception($"http request fail: {link.Substring(0,link.IndexOf('?'))}\n{e}");
// after — safe truncation
int q = link.IndexOf('?');
string safeUrl = q >= 0 ? link.Substring(0, q) : link;
throw new Exception($"http request fail: {safeUrl}\n{e}"); Defensive patterns
Strategy: try-catch
Try / catch
string text;
try { text = await CoroutineHelper.HttpGet(url); }
catch (Exception e) { Log.Error($"HttpGet failed for {url}: {e.Message}"); /* fallback */ return; } Prevention
- Fix the latent IndexOf('?') bug so links without a query string don't crash the error formatter.
- Validate the URL (scheme, host) before calling HttpGet.
- Add a timeout/retry policy around HttpGet for flaky networks.
When it happens
Trigger: HttpGet is awaited and the request fails (no network, server down, DNS failure, HTTP error code). Additionally, if the link passed to HttpGet has no '?' character, the error-formatting line crashes inside the catch block with a different exception than intended.
Common situations: Backend/auth server unreachable during client startup; a URL built without a query string passed to HttpGet; a redirect or certificate error from UnityWebRequest; WebGL build hitting CORS.
Related errors
- 命令行格式错误! {error}
- http request fail: {link.Substring(0,link.IndexOf('?'))}\n{e
- 请先在cmd中运行: netsh http add urlacl url=http://*:你的address中的端口/
- RouterManager dynamic http bind failed after 10 attempts.
- btenv not found key: {key} {typeof(T).FullName}
AI-assisted analysis of egametang/ET@5cab01f7a8 (2026-08-13).
Data as JSON: /api/errors/8c61fd84e9829e50.
Report an issue: GitHub.