Compare commits

...
Author SHA1 Message Date
l0ng-ai 57ec7fb190 fix(plugins): say why a marketplace download failed
A failed plugin download, marketplace read or plugin network request reported only
reqwest's top-level message ("error sending request for url (...)"), with the URL twice
and without the cause. They now carry the error's causes (DNS, connection refused, TLS,
...) the way the HTTP client already does; the MCP server requests of the agent panel too.
2026-11-17 00:42:30 +08:00
4 changed files with 18 additions and 4 deletions

No files matched your search

+4 -1
View File
@@ -712,7 +712,10 @@ async fn probe_http_mcp_server(server: &ide_core::settings::AgentMcpServer) -> M
if let Some(sid) = session_id.as_deref() {
req = req.header("Mcp-Session-Id", sid);
}
let resp = req.send().await.map_err(|e| format!("Request to `{url}` failed: {e}"))?;
let resp = req
.send()
.await
.map_err(|e| format!("Request to `{url}` failed: {}", ide_http::client::describe(&e.without_url())))?;
let status = resp.status();
let next_session =
resp.headers().get("mcp-session-id").and_then(|v| v.to_str().ok()).map(str::to_owned).or(session_id);
+1 -1
View File
@@ -234,7 +234,7 @@ fn network_error(error: reqwest::Error) -> HostError {
}
source = e.source();
}
HostError::Failed(error.to_string())
HostError::Failed(ide_http::client::describe(&error))
}
fn redirect_capability(from: &reqwest::Url, to: &reqwest::Url) -> Result<Capability, String> {
+12 -1
View File
@@ -134,7 +134,8 @@ fn read_remote(url: &str, max: usize, deadline: Duration) -> Result<Vec<u8>, Str
super::api::net_runtime().block_on(async move {
let failed = |e: reqwest::Error| match e.is_timeout() {
true => format!("{url}: no answer in time"),
false => format!("{url}: {e}"),
// With its cause: "error sending request" alone does not say what failed.
false => format!("{url}: {}", ide_http::client::describe(&e.without_url())),
};
let too_large = || format!("{url}: larger than {} MiB", max >> 20);
let mut response = client.get(url).timeout(deadline).send().await.map_err(failed)?;
@@ -587,6 +588,16 @@ mod tests {
assert!(reachable_from("/srv/market/index.json", "/srv/market/a.oiplugin"));
}
#[test]
fn a_failed_read_says_why() {
// A port nothing listens on: refused.
let port = std::net::TcpListener::bind("127.0.0.1:0").unwrap().local_addr().unwrap().port();
let url = format!("http://127.0.0.1:{port}/a.oiplugin");
let err = read_url(&url, 1 << 20).unwrap_err();
assert_eq!(err.matches(&url).count(), 1, "{err}");
assert!(err.to_lowercase().contains("refused"), "{err}");
}
#[test]
fn a_server_that_stops_answering_does_not_hold_the_read() {
use std::io::{BufRead, BufReader, Write};
+1 -1
View File
@@ -109,7 +109,7 @@ pub async fn check_connection(proxy: &ProxySettings, url: &str, cancel: &Cancell
}
/// reqwest errors with their causes ("error sending request: … connection refused").
pub(crate) fn describe(e: &reqwest::Error) -> String {
pub fn describe(e: &reqwest::Error) -> String {
use std::error::Error;
let mut msg = e.to_string();
let mut source = e.source();