Skip to content

Commit

Permalink
Update error message to not start with capital letters
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Apr 20, 2023
1 parent 4d401bd commit e0276ca
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 51 deletions.
104 changes: 54 additions & 50 deletions src/cargo/util/toml_mut/dependency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,68 +225,72 @@ impl Dependency {
(key.to_owned(), None)
};

let source: Source =
if let Some(git) = table.get("git") {
let mut src = GitSource::new(
git.as_str()
.ok_or_else(|| invalid_type(key, "git", git.type_name(), "string"))?,
);
if let Some(value) = table.get("branch") {
src = src.set_branch(value.as_str().ok_or_else(|| {
let source: Source = if let Some(git) = table.get("git") {
let mut src = GitSource::new(
git.as_str()
.ok_or_else(|| invalid_type(key, "git", git.type_name(), "string"))?,
);
if let Some(value) = table.get("branch") {
src =
src.set_branch(value.as_str().ok_or_else(|| {
invalid_type(key, "branch", value.type_name(), "string")
})?);
}
if let Some(value) = table.get("tag") {
src = src.set_tag(value.as_str().ok_or_else(|| {
}
if let Some(value) = table.get("tag") {
src =
src.set_tag(value.as_str().ok_or_else(|| {
invalid_type(key, "tag", value.type_name(), "string")
})?);
}
if let Some(value) = table.get("rev") {
src = src.set_rev(value.as_str().ok_or_else(|| {
}
if let Some(value) = table.get("rev") {
src =
src.set_rev(value.as_str().ok_or_else(|| {
invalid_type(key, "rev", value.type_name(), "string")
})?);
}
if let Some(value) = table.get("version") {
src = src.set_version(value.as_str().ok_or_else(|| {
invalid_type(key, "version", value.type_name(), "string")
})?);
}
src.into()
} else if let Some(path) = table.get("path") {
let path = crate_root
}
if let Some(value) = table.get("version") {
src = src.set_version(value.as_str().ok_or_else(|| {
invalid_type(key, "version", value.type_name(), "string")
})?);
}
src.into()
} else if let Some(path) = table.get("path") {
let path =
crate_root
.join(path.as_str().ok_or_else(|| {
invalid_type(key, "path", path.type_name(), "string")
})?);
let mut src = PathSource::new(path);
if let Some(value) = table.get("version") {
src = src.set_version(value.as_str().ok_or_else(|| {
invalid_type(key, "version", value.type_name(), "string")
})?);
}
src.into()
} else if let Some(version) = table.get("version") {
let src = RegistrySource::new(version.as_str().ok_or_else(|| {
let mut src = PathSource::new(path);
if let Some(value) = table.get("version") {
src = src.set_version(value.as_str().ok_or_else(|| {
invalid_type(key, "version", value.type_name(), "string")
})?);
}
src.into()
} else if let Some(version) = table.get("version") {
let src =
RegistrySource::new(version.as_str().ok_or_else(|| {
invalid_type(key, "version", version.type_name(), "string")
})?);
src.into()
} else if let Some(workspace) = table.get("workspace") {
let workspace_bool = workspace.as_bool().ok_or_else(|| {
invalid_type(key, "workspace", workspace.type_name(), "bool")
})?;
if !workspace_bool {
anyhow::bail!("`{key}.workspace = false` is unsupported")
}
let src = WorkspaceSource::new();
src.into()
} else {
let mut msg = format!("Unrecognized dependency source for `{key}`");
if table.is_empty() {
msg.push_str(
", expected a table with a `version`, `git`, `path`, or `workspace` key",
src.into()
} else if let Some(workspace) = table.get("workspace") {
let workspace_bool = workspace
.as_bool()
.ok_or_else(|| invalid_type(key, "workspace", workspace.type_name(), "bool"))?;
if !workspace_bool {
anyhow::bail!("`{key}.workspace = false` is unsupported")
}
let src = WorkspaceSource::new();
src.into()
} else {
let mut msg = format!("unrecognized dependency source for `{key}`");
if table.is_empty() {
msg.push_str(
", expected a local path, Git repository, version, or workspace dependency to be specified",
);
}
anyhow::bail!(msg);
};
}
anyhow::bail!(msg);
};
let registry = if let Some(value) = table.get("registry") {
Some(
value
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite/cargo_add/empty_dep_table/stderr.log
Original file line number Diff line number Diff line change
@@ -1 +1 @@
error: Unrecognized dependency source for `your-face`, expected a table with a `version`, `git`, `path`, or `workspace` key
error: unrecognized dependency source for `your-face`, expected a local path, Git repository, version, or workspace dependency to be specified

0 comments on commit e0276ca

Please sign in to comment.