Skip to content

Commit

Permalink
Fix incompatible result types via map_err
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholastmosher committed Aug 8, 2019
1 parent 6574cf3 commit cbd158d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
8 changes: 5 additions & 3 deletions capnpc/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1859,7 +1859,8 @@ pub fn generate_code<T>(mut inp: T, out_dir: &::std::path::Path) -> ::capnp::Res
let requested = ::std::path::PathBuf::from(requested_file.get_filename()?);
filepath.push(requested);
if let Some(parent) = filepath.parent() {
::std::fs::create_dir_all(parent)?;
::std::fs::create_dir_all(parent)
.map_err(|err| ::capnp::Error::failed(err.to_string()))?;
}

let root_name = path_to_stem_string(&filepath)?.replace("-", "_");
Expand All @@ -1878,12 +1879,13 @@ pub fn generate_code<T>(mut inp: T, out_dir: &::std::path::Path) -> ::capnp::Res
// would not include `filepath`.
match ::std::fs::File::create(&filepath) {
Ok(ref mut writer) => {
writer.write_all(text.as_bytes())?;
writer.write_all(text.as_bytes())
.map_err(|err| ::capnp::Error::failed(err.to_string()))?;
}
Err(e) => {
let _ = writeln!(&mut ::std::io::stderr(),
"could not open file {:?} for writing: {}", filepath, e);
return Err(e.into());
return Err(::capnp::Error::failed(e.to_string()));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions capnpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ pub enum RustEdition {
}

fn run_command(mut command: ::std::process::Command, path: &PathBuf) -> ::capnp::Result<()> {
let mut p = command.spawn()?;
let mut p = command.spawn().map_err(|err| capnp::Error::failed(err.to_string()))?;
crate::codegen::generate_code(p.stdout.take().unwrap(), path.as_path())?;
let exit_status = p.wait()?;
let exit_status = p.wait().map_err(|err| ::capnp::Error::failed(err.to_string()))?;
if !exit_status.success() {
Err(::capnp::Error::failed(format!(
"Non-success exit status: {}",
Expand Down

0 comments on commit cbd158d

Please sign in to comment.