Skip to content
Snippets Groups Projects
Commit ae6a1730 authored by Udo Eisenbarth's avatar Udo Eisenbarth :speech_balloon:
Browse files

Improve error handling

parent d80d9dd7
No related branches found
No related tags found
No related merge requests found
#[derive(Debug, Clone)]
pub struct OpossumError;
\ No newline at end of file
pub enum OpossumError {
OpticScenery(String),
OpticGroup(String),
Other(String)
}
\ No newline at end of file
......@@ -31,15 +31,15 @@ impl NodeGroup {
target_node: NodeIndex,
) -> Result<EdgeIndex> {
if self.g.node_weight(src_node).is_none() {
return Err(OpossumError);
return Err(OpossumError::OpticGroup("source node with gievn index does not exist".into()));
}
if self.g.node_weight(target_node).is_none() {
return Err(OpossumError);
return Err(OpossumError::OpticGroup("target node with given index does not exist".into()));
}
let edge_index = self.g.add_edge(src_node, target_node, ());
if is_cyclic_directed(&self.g) {
self.g.remove_edge(edge_index);
return Err(OpossumError);
return Err(OpossumError::OpticGroup("connecting the given nodes would form a loop".into()));
}
Ok(edge_index)
}
......
......@@ -45,15 +45,15 @@ impl OpticScenery {
target_node: NodeIndex,
) -> Result<EdgeIndex> {
if self.g.node_weight(src_node).is_none() {
return Err(OpossumError);
return Err(OpossumError::OpticScenery("source node with gievn index does not exist".into()));
}
if self.g.node_weight(target_node).is_none() {
return Err(OpossumError);
return Err(OpossumError::OpticScenery("target node with given index does not exist".into()));
}
let edge_index = self.g.add_edge(src_node, target_node, ());
if is_cyclic_directed(&self.g) {
self.g.remove_edge(edge_index);
return Err(OpossumError);
return Err(OpossumError::OpticScenery("connecting the given nodes would form a loop".into()));
}
Ok(edge_index)
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment