Skip to content

Commit

Permalink
fix(nargo): Indicate which TOML file is missing package name
Browse files Browse the repository at this point in the history
  • Loading branch information
phated committed Aug 4, 2023
1 parent 1c991d0 commit 07c03b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 23 deletions.
3 changes: 3 additions & 0 deletions crates/nargo_cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,7 @@ pub(crate) enum ManifestError {

#[error("Package `{0}` has type `bin` but you cannot depend on binary packages")]
BinaryDependency(CrateName),

#[error("Missing `name` field in {toml}")]
MissingNameField { toml: PathBuf },
}
29 changes: 6 additions & 23 deletions crates/nargo_cli/src/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ struct PackageConfig {

impl PackageConfig {
fn resolve_to_package(&self, root_dir: &Path) -> Result<Package, ManifestError> {
let name = self.package.name.parse().map_err(|_| ManifestError::InvalidPackageName)?;
let name = if let Some(name) = &self.package.name {
name.parse().map_err(|_| ManifestError::InvalidPackageName)?
} else {
return Err(ManifestError::MissingNameField { toml: root_dir.join("Nargo.toml") });
};

let mut dependencies: BTreeMap<CrateName, Dependency> = BTreeMap::new();
for (name, dep_config) in self.dependencies.iter() {
Expand Down Expand Up @@ -113,8 +117,7 @@ struct WorkspaceConfig {
#[allow(dead_code)]
#[derive(Default, Debug, Deserialize, Clone)]
struct PackageMetadata {
#[serde(default = "panic_missing_name")]
name: String,
name: Option<String>,
#[serde(alias = "type")]
package_type: Option<String>,
description: Option<String>,
Expand All @@ -129,26 +132,6 @@ struct PackageMetadata {
license: Option<String>,
}

// TODO: Remove this after a couple of breaking releases (added in 0.10.0)
fn panic_missing_name() -> String {
panic!(
r#"
Failed to parse `Nargo.toml`.
`Nargo.toml` now requires a "name" field for Noir packages.
```toml
[package]
name = "package_name"
```
Modify your `Nargo.toml` similarly to above and rerun the command.
"#
)
}

#[derive(Debug, Deserialize, Clone)]
#[serde(untagged)]
/// Enum representing the different types of ways to
Expand Down

0 comments on commit 07c03b4

Please sign in to comment.