Skip to content

Commit

Permalink
Improve error messages from bundler
Browse files Browse the repository at this point in the history
  • Loading branch information
lpenz committed Jun 11, 2024
1 parent a7d1ead commit 677baf4
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/bundler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use std::io::BufWriter;
use std::io::Write;
use std::path::{Path, PathBuf};

use anyhow::{anyhow, Result};
use anyhow::{anyhow, Context, Result};
use cargo_toml;
use lazy_static::lazy_static;
use regex::Regex;
Expand Down Expand Up @@ -90,19 +90,28 @@ impl<'a> Bundler<'a> {
self.binrs_filename
)
})?,
);
)
.canonicalize()
.with_context(|| String::from("error canonicalizing base dir"))?;
let cargo_filename = self.basedir.join("Cargo.toml");
let cargo = cargo_toml::Manifest::from_path(&cargo_filename)?;
let cargo = cargo_toml::Manifest::from_path(&cargo_filename)
.with_context(|| format!("error parsing {:?}", cargo_filename))?;
self._crate_name = cargo
.package
.ok_or_else(|| anyhow!("Could not get crate name from {}", cargo_filename.display()))?
.name
.replace('-', "_");
self.binrs()?;
self.binrs()
.with_context(|| format!("error building bin.rs {:?}", self.binrs_filename))?;
if let Some(bundle_filename) = self.bundle_filename {
println!("rerun-if-changed={}", bundle_filename.display());
}
self.bundle_file.flush()?;
self.bundle_file.flush().with_context(|| {
format!(
"error while flushing bundle_file {:?}",
self.bundle_filename
)
})?;
Ok(())
}

Expand Down Expand Up @@ -180,7 +189,7 @@ impl<'a> Bundler<'a> {
mod_import: &str,
lvl: usize,
) -> Result<()> {
let mod_filenames0 = vec![
let mod_filenames0 = [
format!("src/{}.rs", mod_path),
format!("src/{}/mod.rs", mod_path),
];
Expand Down

0 comments on commit 677baf4

Please sign in to comment.