Improve tracing when encountering invalid requires-python values (#1568)
Unsure what the easiest way to test this is, it is hard to publish invalid requires-python specifiers with hatchling
This commit is contained in:
@@ -10,8 +10,8 @@ use pypi_types::{DistInfoMetadata, Hashes, Yanked};
|
||||
/// Error converting [`pypi_types::File`] to [`distribution_type::File`].
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FileConversionError {
|
||||
#[error("Invalid 'requires-python' value")]
|
||||
VersionSpecifiersParseError(#[from] VersionSpecifiersParseError),
|
||||
#[error("Failed to parse 'requires-python': {0}")]
|
||||
RequiresPython(String, #[source] VersionSpecifiersParseError),
|
||||
#[error("Failed to parse URL: {0}")]
|
||||
Url(String, #[source] url::ParseError),
|
||||
}
|
||||
@@ -44,7 +44,10 @@ impl File {
|
||||
dist_info_metadata: file.dist_info_metadata,
|
||||
filename: file.filename,
|
||||
hashes: file.hashes,
|
||||
requires_python: file.requires_python.transpose()?,
|
||||
requires_python: file
|
||||
.requires_python
|
||||
.transpose()
|
||||
.map_err(|err| FileConversionError::RequiresPython(err.line().clone(), err))?,
|
||||
size: file.size,
|
||||
upload_time_utc_ms: file.upload_time.map(|dt| dt.timestamp_millis()),
|
||||
url: if file.url.contains("://") {
|
||||
|
||||
@@ -232,6 +232,13 @@ impl std::fmt::Display for VersionSpecifiersParseError {
|
||||
}
|
||||
}
|
||||
|
||||
impl VersionSpecifiersParseError {
|
||||
/// The string that failed to parse
|
||||
pub fn line(&self) -> &String {
|
||||
&self.inner.line
|
||||
}
|
||||
}
|
||||
|
||||
impl std::error::Error for VersionSpecifiersParseError {}
|
||||
|
||||
/// A version range such such as `>1.2.3`, `<=4!5.6.7-a8.post9.dev0` or `== 4.1.*`. Parse with
|
||||
|
||||
Reference in New Issue
Block a user