Skip to content

Commit fc49bc5

Browse files
committed
Improve error handling
1 parent 3760561 commit fc49bc5

1 file changed

Lines changed: 13 additions & 14 deletions

File tree

crates/uv-python/src/downloads.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,10 @@ impl ManagedPythonDownloadList {
10251025
cache: &Cache,
10261026
python_downloads_json_url: Option<&str>,
10271027
) -> Result<Self, Error> {
1028-
// Although read_url() handles file:// URLs and converts them to local file reads, here we
1029-
// want to also support parsing bare filenames like "/tmp/py.json", not just
1030-
// "file:///tmp/py.json". Note that "C:\Temp\py.json" should be considered a filename, even
1031-
// though Url::parse would successfully misparse it as a URL with scheme "C".
1028+
// file:// URLs are converted to local file reads, and we also support parsing bare
1029+
// filenames like "/tmp/py.json", not just "file:///tmp/py.json". Note that
1030+
// "C:\Temp\py.json" should be considered a filename, even though Url::parse would
1031+
// successfully misparse it as a URL with scheme "C".
10321032
enum Source<'a> {
10331033
BuiltIn,
10341034
Path(Cow<'a, Path>),
@@ -1135,19 +1135,18 @@ async fn fetch_downloads_from_url(
11351135
Connectivity::Offline => CacheControl::AllowStale,
11361136
};
11371137

1138-
let start = Instant::now();
11391138
let request = client
11401139
.uncached()
11411140
.for_host(url)
11421141
.get(Url::from(url.clone()))
11431142
.build()
1144-
.map_err(|err| Error::from_reqwest(url.clone(), err, None, start))?;
1143+
.map_err(|err| Error::NetworkError(url.clone(), WrappedReqwestError::from(err)))?;
11451144

11461145
let response_callback = async |response: Response| {
11471146
let bytes = response
11481147
.bytes()
11491148
.await
1150-
.map_err(|err| Error::from_reqwest(url.clone(), err, None, start))?;
1149+
.map_err(|err| Error::NetworkError(url.clone(), WrappedReqwestError::from(err)))?;
11511150
parse_downloads_json(&bytes, url.to_string())
11521151
};
11531152

@@ -1160,13 +1159,13 @@ async fn fetch_downloads_from_url(
11601159
err,
11611160
retries,
11621161
duration,
1163-
} => {
1164-
if retries > 0 {
1165-
err.into_retried(retries, duration)
1166-
} else {
1167-
err
1168-
}
1169-
}
1162+
} => match err {
1163+
// Avoid double-wrapping errors.
1164+
err @ (Error::InvalidPythonDownloadsJSON(..)
1165+
| Error::UnsupportedPythonDownloadsJSON(..)) => err,
1166+
err if retries > 0 => err.into_retried(retries, duration),
1167+
err => err,
1168+
},
11701169
})
11711170
}
11721171

0 commit comments

Comments
 (0)