Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve config.toml error msg #1155

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion rye/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ impl Config {
if let Some(sources) = self.doc.get("sources").map(|x| toml::iter_tables(x)) {
for source in sources {
let source = source.context("invalid value for source in config.toml")?;
let source_ref = SourceRef::from_toml_table(source)?;
let source_ref = SourceRef::from_toml_table(source)
.context("invalid source definition in config.toml")?;
if source_ref.name == "default" {
need_default = false;
}
Expand Down
10 changes: 6 additions & 4 deletions rye/src/pyproject.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,12 @@ impl SourceRef {
.get("name")
.and_then(|x| x.as_str())
.map(|x| x.to_string())
.ok_or_else(|| anyhow!("expected name"))?;
.ok_or_else(|| anyhow!("expected source.name"))?;
let url = source
.get("url")
.and_then(|x| x.as_str())
.map(|x| x.to_string())
.ok_or_else(|| anyhow!("expected url"))?;
.ok_or_else(|| anyhow!("expected source.url"))?;
let verify_ssl = source
.get("verify_ssl")
.and_then(|x| x.as_bool())
Expand All @@ -174,7 +174,7 @@ impl SourceRef {
.get("type")
.and_then(|x| x.as_str())
.map_or(Ok(SourceRefType::Index), |x| x.parse::<SourceRefType>())
.context("invalid value for type")?;
.context("invalid value for source.type")?;
Ok(SourceRef {
name,
url,
Expand Down Expand Up @@ -1252,7 +1252,8 @@ fn get_sources(doc: &DocumentMut) -> Result<Vec<SourceRef>, Error> {
{
for source in sources {
let source = source.context("invalid value for pyproject.toml's tool.rye.sources")?;
let source_ref = SourceRef::from_toml_table(source)?;
let source_ref = SourceRef::from_toml_table(source)
.context("invalid source definition in pyproject.toml")?;
rv.push(source_ref);
}
}
Expand Down Expand Up @@ -1299,6 +1300,7 @@ fn get_project_metadata(path: &Path) -> Result<Metadata, Error> {
}
serde_json::from_slice(&metadata.stdout).map_err(Into::into)
}

/// Represents expanded sources.
#[derive(Debug, Clone, Serialize)]
pub struct ExpandedSources {
Expand Down