From 07c03b45c985d9dd3c0f385a035a1a1f9985ff21 Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 3 Aug 2023 15:04:34 -0700 Subject: [PATCH] fix(nargo): Indicate which TOML file is missing package name --- crates/nargo_cli/src/errors.rs | 3 +++ crates/nargo_cli/src/manifest.rs | 29 ++++++----------------------- 2 files changed, 9 insertions(+), 23 deletions(-) diff --git a/crates/nargo_cli/src/errors.rs b/crates/nargo_cli/src/errors.rs index 45d2dbae827..78db35728a4 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -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 }, } diff --git a/crates/nargo_cli/src/manifest.rs b/crates/nargo_cli/src/manifest.rs index c376c85b441..1f522a732d8 100644 --- a/crates/nargo_cli/src/manifest.rs +++ b/crates/nargo_cli/src/manifest.rs @@ -22,7 +22,11 @@ struct PackageConfig { impl PackageConfig { fn resolve_to_package(&self, root_dir: &Path) -> Result { - 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 = BTreeMap::new(); for (name, dep_config) in self.dependencies.iter() { @@ -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, #[serde(alias = "type")] package_type: Option, description: Option, @@ -129,26 +132,6 @@ struct PackageMetadata { license: Option, } -// 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