Browse Source

Better exception handling

Yentl Van Tendeloo 7 years ago
parent
commit
1b80de98c8
4 changed files with 48 additions and 24 deletions
  1. 0 1
      bootstrap/core_algorithm.alc
  2. 2 21
      unit/test_all.py
  3. 20 0
      wrappers/classes/modelverse.xml
  4. 26 2
      wrappers/modelverse_SCCD.py

+ 0 - 1
bootstrap/core_algorithm.alc

@@ -1672,7 +1672,6 @@ String function cmd_model_modify(model_name : String, metamodel_name : String):
 				Element new_model
 				new_model = get_full_model(model_id, get_entry_id(metamodel_name))
 				if (element_eq(new_model, read_root())):
-					log("Failed to find conformance...")
 					return "Conformance hierarchy unknown for: " + model_name!
 				modify(new_model, allow_write(current_user_id, model_id))
 				if (allow_write(current_user_id, model_id)):

+ 2 - 21
unit/test_all.py

@@ -178,61 +178,42 @@ class TestModelverse(unittest.TestCase):
         instantiate("users/user/test/a", "Finish")
         assert verify("users/user/test/a", "formalisms/ProcessModel") == "OK"
 
-    """
     def test_op_permission_modify(self):
         model_add("users/user/test/a", "formalisms/SimpleClassDiagrams")
-        print("1")
         assert model_list_full("users/user/test") == set([("a", "user", "nobody", "200")])
 
         # Check that we can read
         element_list_nice("users/user/test/a")
-        print("2")
         # Check that we can write
         instantiate("users/user/test/a", "Class")
-        print("3")
 
         assert permission_modify("users/user/test/a", "100") == None
-        print("4")
         assert model_list_full("users/user/test") == set([("a", "user", "nobody", "100")])
-        print("5")
         # Check that we can read
         element_list_nice("users/user/test/a")
         # Check that we can't write
-        print("6")
         try:
             instantiate("users/user/test/a", "Class")
-            print("7")
             self.fail()
         except WritePermissionDenied:
-            print("8")
             pass
 
-        print("8a")
         assert permission_modify("users/user/test/a", "000") == None
-        print("9")
         assert model_list_full("users/user/test") == set([("a", "user", "nobody", "000")])
-        print("10")
         # Check that we can't read
         try:
             element_list_nice("users/user/test/a")
-            print("11")
             self.fail()
         except ReadPermissionDenied:
-            print("12")
             pass
-        except Exception as e:
-            import traceback
-            traceback.print_exc()
         # Check that we can't write
         try:
             instantiate("users/user/test/a", "Class")
-            print("13")
             self.fail()
         except WritePermissionDenied:
-            print("14")
             pass
-        print("15")
-    """
+        except ReadPermissionDenied:
+            pass
 
     """
     def test_op_model_add(self):

+ 20 - 0
wrappers/classes/modelverse.xml

@@ -2036,6 +2036,26 @@
 
                         <transition cond="self.expect_response('Model loaded, ready for commands!', pop=True)" target="../../wait_for_action/modelling/recognized/manual"/>
 
+                        <transition cond="self.expect_response_partial('Location not found: ', pop=False)" target="../../wait_for_action/megamodelling">
+                            <raise event="exception">
+                                <parameter expr="'UnknownLocation'"/>
+                                <parameter expr="'No such location: ' + self.responses.pop(0)"/>
+                            </raise>
+                            <script>
+                                self.actions.pop(0)
+                            </script>
+                        </transition>
+
+                        <transition cond="self.expect_response_partial('Read permission denied to: ', pop=False)" target="../../wait_for_action/megamodelling">
+                            <raise event="exception">
+                                <parameter expr="'ReadPermissionDenied'"/>
+                                <parameter expr="'No permission to read model ' + self.responses.pop(0)"/>
+                            </raise>
+                            <script>
+                                self.actions.pop(0)
+                            </script>
+                        </transition>
+
                         <transition cond="self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)" target="../../wait_for_action/megamodelling">
                             <raise event="exception">
                                 <parameter expr="'UnknownMetamodellingHierarchy'"/>

+ 26 - 2
wrappers/modelverse_SCCD.py

@@ -1,7 +1,7 @@
 """
 Generated by Statechart compiler by Glenn De Jonghe, Joeri Exelmans, Simon Van Mierlo, and Yentl Van Tendeloo (for the inspiration)
 
-Date:   Thu Jun  7 12:11:58 2018
+Date:   Thu Jun  7 13:50:59 2018
 
 Model author: Yentl Van Tendeloo
 Model name:   MvK Server
@@ -1664,6 +1664,16 @@ class Modelverse(RuntimeClassBase):
         _initialized_behaviour_going_manual_OK_1.setTrigger(None)
         _initialized_behaviour_going_manual_OK_1.setGuard(self._initialized_behaviour_going_manual_OK_1_guard)
         self.states["/initialized/behaviour/going_manual/OK"].addTransition(_initialized_behaviour_going_manual_OK_1)
+        _initialized_behaviour_going_manual_OK_2 = Transition(self, self.states["/initialized/behaviour/going_manual/OK"], [self.states["/initialized/behaviour/wait_for_action/megamodelling"]])
+        _initialized_behaviour_going_manual_OK_2.setAction(self._initialized_behaviour_going_manual_OK_2_exec)
+        _initialized_behaviour_going_manual_OK_2.setTrigger(None)
+        _initialized_behaviour_going_manual_OK_2.setGuard(self._initialized_behaviour_going_manual_OK_2_guard)
+        self.states["/initialized/behaviour/going_manual/OK"].addTransition(_initialized_behaviour_going_manual_OK_2)
+        _initialized_behaviour_going_manual_OK_3 = Transition(self, self.states["/initialized/behaviour/going_manual/OK"], [self.states["/initialized/behaviour/wait_for_action/megamodelling"]])
+        _initialized_behaviour_going_manual_OK_3.setAction(self._initialized_behaviour_going_manual_OK_3_exec)
+        _initialized_behaviour_going_manual_OK_3.setTrigger(None)
+        _initialized_behaviour_going_manual_OK_3.setGuard(self._initialized_behaviour_going_manual_OK_3_guard)
+        self.states["/initialized/behaviour/going_manual/OK"].addTransition(_initialized_behaviour_going_manual_OK_3)
         
         # transition /initialized/behaviour/going_scripted
         _initialized_behaviour_going_scripted_0 = Transition(self, self.states["/initialized/behaviour/going_scripted"], [self.states["/initialized/behaviour/wait_for_action/modelling/recognized/scripted"]])
@@ -3367,11 +3377,25 @@ class Modelverse(RuntimeClassBase):
         return self.expect_response('Model loaded, ready for commands!', pop=True)
     
     def _initialized_behaviour_going_manual_OK_1_exec(self, parameters):
+        self.raiseInternalEvent(Event("exception", None, ['UnknownLocation', 'No such location: ' + self.responses.pop(0)]))
+        self.actions.pop(0)
+    
+    def _initialized_behaviour_going_manual_OK_1_guard(self, parameters):
+        return self.expect_response_partial('Location not found: ', pop=False)
+    
+    def _initialized_behaviour_going_manual_OK_2_exec(self, parameters):
+        self.raiseInternalEvent(Event("exception", None, ['ReadPermissionDenied', 'No permission to read model ' + self.responses.pop(0)]))
+        self.actions.pop(0)
+    
+    def _initialized_behaviour_going_manual_OK_2_guard(self, parameters):
+        return self.expect_response_partial('Read permission denied to: ', pop=False)
+    
+    def _initialized_behaviour_going_manual_OK_3_exec(self, parameters):
         self.raiseInternalEvent(Event("exception", None, ['UnknownMetamodellingHierarchy', 'Conformance relation not found']))
         self.responses.pop(0)
         self.actions.pop(0)
     
-    def _initialized_behaviour_going_manual_OK_1_guard(self, parameters):
+    def _initialized_behaviour_going_manual_OK_3_guard(self, parameters):
         return self.expect_response_partial('Conformance hierarchy unknown for: ', pop=False)
     
     def _initialized_behaviour_leaving_manual_0_guard(self, parameters):