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

fix(nargo): Indicate which TOML file is missing package name #2177

Merged
merged 1 commit into from
Aug 4, 2023
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: 3 additions & 0 deletions crates/nargo_cli/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
#[error("Nargo.toml is badly formed, could not parse.\n\n {0}")]
MalformedFile(#[from] toml::de::Error),

#[error("Unxpected workspace definition found in {0}")]

Check warning on line 123 in crates/nargo_cli/src/errors.rs

View workflow job for this annotation

GitHub Actions / Spellcheck / Spellcheck

Unknown word (Unxpected)
UnexpectedWorkspace(PathBuf),

#[error("Cannot find file {0} which is required due to specifying the `{1}` package type")]
Expand All @@ -142,4 +142,7 @@

#[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