Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoseph Frazer <joseph.frazer@ryansg.com>2020-03-07 11:18:56 -0500
committerJoseph Frazer <joseph.frazer@ryansg.com>2020-03-09 08:23:13 -0400
commit01e7d3e56059fefeb862028e5868f947a042dcd4 (patch)
tree92d37e43ade05c026e96fcba88643ae55aa327ec /tamer/src/ld/poc.rs
parentf373a00a80a4a366573d178911f455561fc2c0ff (diff)
downloadtame-01e7d3e56059fefeb862028e5868f947a042dcd4.tar.gz
tame-01e7d3e56059fefeb862028e5868f947a042dcd4.tar.bz2
tame-01e7d3e56059fefeb862028e5868f947a042dcd4.zip
[DEV-7134] Propagate errors from the writer
When an error occurs during the XML writing, they should be shown to the user.
Diffstat (limited to 'tamer/src/ld/poc.rs')
-rw-r--r--tamer/src/ld/poc.rs28
1 files changed, 13 insertions, 15 deletions
diff --git a/tamer/src/ld/poc.rs b/tamer/src/ld/poc.rs
index 6e0a7fe..52f4366 100644
--- a/tamer/src/ld/poc.rs
+++ b/tamer/src/ld/poc.rs
@@ -294,14 +294,14 @@ fn get_interner_value<'a, 'i, I: Interner<'i>>(
depgraph: &'a LinkerAsg<'i>,
interner: &'i I,
name: &str,
-) -> &'a Object<'i> {
- depgraph
- .get(
- depgraph
- .lookup(interner.intern(name))
- .unwrap_or_else(|| panic!("missing identifier: {}", name)),
- )
- .expect("Could not get interner value")
+) -> Result<&'a Object<'i>, Box<dyn Error>> {
+ match depgraph.lookup(interner.intern(name)) {
+ Some(frag) => match depgraph.get(frag) {
+ Some(result) => Ok(result),
+ None => Err(XmloError::MissingFragment(String::from(name)).into()),
+ },
+ None => Err(XmloError::MissingFragment(String::from(name)).into()),
+ }
}
fn output_xmle<'a, 'i, I: Interner<'i>>(
@@ -317,12 +317,12 @@ fn output_xmle<'a, 'i, I: Interner<'i>>(
depgraph,
interner,
&String::from(":map:___head"),
- ));
+ )?);
sorted.map.push_tail(get_interner_value(
depgraph,
interner,
&String::from(":map:___tail"),
- ));
+ )?);
}
if !sorted.retmap.is_empty() {
@@ -330,19 +330,17 @@ fn output_xmle<'a, 'i, I: Interner<'i>>(
depgraph,
interner,
&String::from(":retmap:___head"),
- ));
+ )?);
sorted.retmap.push_tail(get_interner_value(
depgraph,
interner,
&String::from(":retmap:___tail"),
- ));
+ )?);
}
let file = fs::File::create(output)?;
let mut xmle_writer = XmleWriter::new(file);
- xmle_writer
- .write(&sorted, name, &relroot)
- .expect("Could not write xmle output");
+ xmle_writer.write(&sorted, name, &relroot)?;
Ok(())
}