Skip to content

Commit

Permalink
Better error message on failed file creation.
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Mar 13, 2015
1 parent 281475f commit 8372056
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1545,6 +1545,7 @@ pub fn main<T : ::capnp::io::InputStream>(mut inp : T) -> ::std::io::Result<()>
use capnp::serialize;
use capnp::MessageReader;
use std::borrow::ToOwned;
use std::io::Write;

let message = try!(serialize::new_reader(&mut inp, capnp::ReaderOptions::new()));

Expand Down Expand Up @@ -1591,12 +1592,17 @@ pub fn main<T : ::capnp::io::InputStream>(mut inp : T) -> ::std::io::Result<()>

let text = stringify(&lines);

// It would be simpler to use try! instead of a pattern match, but then the error message
// would not include `filepath`.
match ::std::fs::File::create(&filepath) {
Ok(ref mut writer) => {
use std::io::Write;
try!(writer.write_all(text.as_bytes()));
}
Err(e) => {panic!("could not open file for writing: {}", e)}
Err(e) => {
let _ = writeln!(&mut ::std::io::stderr(),
"could not open file {:?} for writing: {}", filepath, e);
return Err(e);
}
}
}
Ok(())
Expand Down

0 comments on commit 8372056

Please sign in to comment.