Mike Gerwitz

Activist for User Freedom

aboutsummaryrefslogtreecommitdiffstats
path: root/tamer
diff options
context:
space:
mode:
authorMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-24 15:54:26 -0400
committerMike Gerwitz <mike.gerwitz@ryansg.com>2020-03-26 09:08:10 -0400
commitb35dd4f4dd6c29ff63ed558caad5c19861913bf1 (patch)
tree8ca1dfb6a1771664d087de810a5b5fc985b90734 /tamer
parent03fa2ffc0b7496b5fd596e1217a50c52c285686d (diff)
downloadtame-b35dd4f4dd6c29ff63ed558caad5c19861913bf1.tar.gz
tame-b35dd4f4dd6c29ff63ed558caad5c19861913bf1.tar.bz2
tame-b35dd4f4dd6c29ff63ed558caad5c19861913bf1.zip
[DEV-7087] TAMER: AsgError: Wrap TransitionError
See next commit.
Diffstat (limited to 'tamer')
-rw-r--r--tamer/src/ir/asg/base.rs7
-rw-r--r--tamer/src/ir/asg/graph.rs35
-rw-r--r--tamer/src/ir/asg/object.rs8
3 files changed, 22 insertions, 28 deletions
diff --git a/tamer/src/ir/asg/base.rs b/tamer/src/ir/asg/base.rs
index 5aea07e..431172b 100644
--- a/tamer/src/ir/asg/base.rs
+++ b/tamer/src/ir/asg/base.rs
@@ -648,9 +648,8 @@ mod test {
// Set up an object to fail redeclaration.
let node = sut.declare(&sym, IdentKind::Meta, src.clone())?;
let obj = sut.get(node).unwrap();
- let msg = String::from("test fail");
- obj.fail_redeclare
- .replace(Some(TransitionError::Incompatible(msg.clone())));
+ let terr = TransitionError::Incompatible(String::from("test fail"));
+ obj.fail_redeclare.replace(Some(terr.clone()));
// Should invoke StubIdentObject::redeclare on the above `obj`.
let result = sut.declare(&sym, IdentKind::Meta, Source::default());
@@ -660,7 +659,7 @@ mod test {
let obj = sut.get(node).unwrap();
assert_eq!(src, obj.given_ident.as_ref().unwrap().2);
- assert_eq!(AsgError::IncompatibleIdent(msg), err);
+ assert_eq!(AsgError::ObjectTransition(terr), err);
Ok(())
} else {
diff --git a/tamer/src/ir/asg/graph.rs b/tamer/src/ir/asg/graph.rs
index c6e3a30..52d83cc 100644
--- a/tamer/src/ir/asg/graph.rs
+++ b/tamer/src/ir/asg/graph.rs
@@ -227,18 +227,12 @@ pub type Node<O> = Option<O>;
/// The caller will know the problem values.
#[derive(Debug, PartialEq)]
pub enum AsgError<Ix: Debug> {
- /// The provided identifier is not in a state that is permitted to
- /// receive a fragment.
+ /// An object could not change state in the manner requested.
///
- /// See [`Asg::set_fragment`] for more information.
- BadFragmentDest(String),
-
- /// An attempt to redeclare an identifier with additional information
- /// has failed because the provided information was not compatible
- /// with the original declaration.
- ///
- /// See [`Asg::declare`] for more information.
- IncompatibleIdent(String),
+ /// See [`Asg::declare`] and [`Asg::set_fragment`] for more
+ /// information.
+ /// See also [`TransitionError`].
+ ObjectTransition(TransitionError),
/// The node was not expected in the current context
UnexpectedNode(String),
@@ -250,12 +244,7 @@ pub enum AsgError<Ix: Debug> {
impl<Ix: Debug> std::fmt::Display for AsgError<Ix> {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
- Self::BadFragmentDest(msg) => {
- write!(fmt, "bad fragment destination: {}", msg)
- }
- Self::IncompatibleIdent(msg) => {
- write!(fmt, "identifier redeclaration failed: {}", msg)
- }
+ Self::ObjectTransition(err) => std::fmt::Display::fmt(&err, fmt),
Self::UnexpectedNode(msg) => {
write!(fmt, "unexpected node: {}", msg)
}
@@ -268,16 +257,16 @@ impl<Ix: Debug> std::fmt::Display for AsgError<Ix> {
impl<Ix: Debug> std::error::Error for AsgError<Ix> {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
- None
+ match self {
+ Self::ObjectTransition(err) => err.source(),
+ _ => None,
+ }
}
}
impl<Ix: Debug> From<TransitionError> for AsgError<Ix> {
- fn from(e: TransitionError) -> Self {
- match e {
- TransitionError::Incompatible(msg) => Self::IncompatibleIdent(msg),
- TransitionError::BadFragmentDest(msg) => Self::BadFragmentDest(msg),
- }
+ fn from(err: TransitionError) -> Self {
+ Self::ObjectTransition(err)
}
}
diff --git a/tamer/src/ir/asg/object.rs b/tamer/src/ir/asg/object.rs
index 2f5684d..2d5836b 100644
--- a/tamer/src/ir/asg/object.rs
+++ b/tamer/src/ir/asg/object.rs
@@ -340,7 +340,7 @@ impl<'i> IdentObjectState<'i, IdentObject<'i>> for IdentObject<'i> {
/// another.
///
/// TODO: Provide enough information to construct a useful message.
-#[derive(Debug, PartialEq)]
+#[derive(Clone, Debug, PartialEq)]
pub enum TransitionError {
/// An attempt to redeclare an identifier with additional information
/// has failed because the provided information was not compatible
@@ -370,6 +370,12 @@ impl std::fmt::Display for TransitionError {
}
}
+impl std::error::Error for TransitionError {
+ fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
+ None
+ }
+}
+
/// Compiled fragment for identifier.
///
/// This represents the text associated with an identifier.