Skip to content

Commit

Permalink
Report error from parsing Cargo.toml
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Sep 22, 2022
1 parent bce5f95 commit d55016a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 7 additions & 7 deletions src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ use std::fs;
use std::path::PathBuf;
use toml::Value;

pub fn get_manifest(manifest_dir: &Directory) -> Manifest {
try_get_manifest(manifest_dir).unwrap_or_default()
}

fn try_get_manifest(manifest_dir: &Directory) -> Result<Manifest, Error> {
pub fn get_manifest(manifest_dir: &Directory) -> Result<Manifest, Error> {
let cargo_toml_path = manifest_dir.join("Cargo.toml");
let manifest_str = fs::read_to_string(cargo_toml_path)?;
let mut manifest: Manifest = toml::from_str(&manifest_str)?;
let mut manifest = (|| {
let manifest_str = fs::read_to_string(&cargo_toml_path)?;
let manifest: Manifest = toml::from_str(&manifest_str)?;
Ok(manifest)
})()
.map_err(|err| Error::GetManifest(cargo_toml_path, Box::new(err)))?;

fix_dependencies(&mut manifest.dependencies, manifest_dir);
fix_dependencies(&mut manifest.dev_dependencies, manifest_dir);
Expand Down
2 changes: 2 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::path::PathBuf;
pub enum Error {
Cargo(io::Error),
CargoFail,
GetManifest(PathBuf, Box<Error>),
Glob(GlobError),
Io(io::Error),
Metadata(serde_json::Error),
Expand All @@ -33,6 +34,7 @@ impl Display for Error {
match self {
Cargo(e) => write!(f, "failed to execute cargo: {}", e),
CargoFail => write!(f, "cargo reported an error"),
GetManifest(path, e) => write!(f, "failed to read manifest {}: {}", path.display(), e),
Glob(e) => write!(f, "{}", e),
Io(e) => write!(f, "{}", e),
Metadata(e) => write!(f, "failed to read cargo metadata: {}", e),
Expand Down
2 changes: 1 addition & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Runner {
}

let source_dir = cargo::manifest_dir()?;
let source_manifest = dependencies::get_manifest(&source_dir);
let source_manifest = dependencies::get_manifest(&source_dir)?;

let mut features = features::find();

Expand Down

0 comments on commit d55016a

Please sign in to comment.