SbyProc: New error_callback instead of exit_callback for failing procs
authorJannis Harder <me@jix.one>
Wed, 15 Jun 2022 10:10:52 +0000 (12:10 +0200)
committerJannis Harder <me@jix.one>
Wed, 15 Jun 2022 11:25:21 +0000 (13:25 +0200)
sbysrc/sby_core.py

index ab10614fc6906f0594dfc2b748d0dbbc91c76f8e..55b582ec883440bf9fcffa36298d1fa506ac325b 100644 (file)
@@ -87,6 +87,7 @@ class SbyProc:
 
         self.output_callback = None
         self.exit_callback = None
+        self.error_callback = None
 
     def register_dep(self, next_proc):
         if self.finished:
@@ -115,6 +116,14 @@ class SbyProc:
         if self.exit_callback is not None:
             self.exit_callback(retcode)
 
+    def handle_error(self, retcode):
+        if self.terminated:
+            return
+        if self.logfile is not None:
+            self.logfile.close()
+        if self.error_callback is not None:
+            self.error_callback(retcode)
+
     def terminate(self, timeout=False):
         if self.task.opt_wait and not timeout:
             return
@@ -185,20 +194,22 @@ class SbyProc:
                 self.task.status = "ERROR"
                 if not self.silent:
                     self.task.log(f"{self.info}: COMMAND NOT FOUND. ERROR.")
+                self.handle_error(self.p.returncode)
                 self.terminated = True
                 self.task.terminate()
                 return
 
-            self.handle_exit(self.p.returncode)
-
             if self.checkretcode and self.p.returncode != 0:
                 self.task.status = "ERROR"
                 if not self.silent:
                     self.task.log(f"{self.info}: task failed. ERROR.")
+                self.handle_error(self.p.returncode)
                 self.terminated = True
                 self.task.terminate()
                 return
 
+            self.handle_exit(self.p.returncode)
+
             self.finished = True
             for next_proc in self.notify:
                 next_proc.poll()
@@ -503,14 +514,15 @@ class SbyTask(SbyConfig):
             proc.checkretcode = True
 
             def instance_hierarchy_callback(retcode):
-                if retcode != 0:
-                    self.precise_prop_status = False
-                    return
                 if self.design_hierarchy == None:
                     with open(f"{self.workdir}/model/design.json") as f:
                         self.design_hierarchy = design_hierarchy(f)
 
+            def instance_hierarchy_error_callback(retcode):
+                self.precise_prop_status = False
+
             proc.exit_callback = instance_hierarchy_callback
+            proc.error_callback = instance_hierarchy_error_callback
 
             return [proc]