From 37e44c2dc1d399b3ebdd27c80e1b118758c68867 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 af427a895d4..79c463506b4 100644 --- a/crates/nargo_cli/src/errors.rs +++ b/crates/nargo_cli/src/errors.rs @@ -147,4 +147,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 adf5000d9f0..379bb50a6fc 100644 --- a/crates/nargo_cli/src/manifest.rs +++ b/crates/nargo_cli/src/manifest.rs @@ -21,7 +21,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() { @@ -134,8 +138,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, entry: Option, @@ -151,26 +154,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