Propagate missing `Cargo.toml` errors instead of unwrapping them

This allows them to be reported to the user, rather than panic and dump a
human-error failure.

Fixes #242
master
Nick Fitzgerald 7 years ago
parent e2e3e49f50
commit ed35e497c7
  1. 17
      src/command/build.rs
  2. 2
      src/command/mod.rs

@ -64,12 +64,15 @@ pub struct BuildOptions {
// build_config: Option<BuildConfig>, // build_config: Option<BuildConfig>,
} }
impl From<BuildOptions> for Build { type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>;
fn from(build_opts: BuildOptions) -> Self {
impl Build {
/// Construct a build command from the given options.
pub fn try_from_opts(build_opts: BuildOptions) -> Result<Self, Error> {
let crate_path = set_crate_path(build_opts.path); let crate_path = set_crate_path(build_opts.path);
let crate_name = manifest::get_crate_name(&crate_path).unwrap(); let crate_name = manifest::get_crate_name(&crate_path)?;
// let build_config = manifest::xxx(&crate_path).xxx(); // let build_config = manifest::xxx(&crate_path).xxx();
Build { Ok(Build {
crate_path, crate_path,
scope: build_opts.scope, scope: build_opts.scope,
disable_dts: build_opts.disable_dts, disable_dts: build_opts.disable_dts,
@ -77,13 +80,9 @@ impl From<BuildOptions> for Build {
debug: build_opts.debug, debug: build_opts.debug,
// build_config, // build_config,
crate_name, crate_name,
})
} }
}
}
type BuildStep = fn(&mut Build, &Step, &Logger) -> Result<(), Error>;
impl Build {
/// Execute this `Build` command. /// Execute this `Build` command.
pub fn run(&mut self, log: &Logger, mode: &BuildMode) -> Result<(), Error> { pub fn run(&mut self, log: &Logger, mode: &BuildMode) -> Result<(), Error> {
let process_steps = Build::get_process_steps(mode); let process_steps = Build::get_process_steps(mode);

@ -84,7 +84,7 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error
"normal" => BuildMode::Normal, "normal" => BuildMode::Normal,
_ => BuildMode::Normal, _ => BuildMode::Normal,
}; };
Build::from(build_opts).run(&log, &build_mode) Build::try_from_opts(build_opts).and_then(|mut b| b.run(&log, &build_mode))
} }
Command::Pack { path } => { Command::Pack { path } => {
info!(&log, "Running pack command..."); info!(&log, "Running pack command...");

Loading…
Cancel
Save