From ab23681832fd63bef7b813da7b2087807f91c462 Mon Sep 17 00:00:00 2001
From: Jan David Mol <mol@astron.nl>
Date: Wed, 7 Apr 2021 16:59:38 +0200
Subject: [PATCH] Log the exceptions thrown by the entry-point commands, and go
 to Fault if an exception is thrown in them (unless we go to Off or Fault)

---
 devices/{ => examples}/HW_device_template.py | 0
 devices/util/hardware_device.py              | 8 +++++++-
 2 files changed, 7 insertions(+), 1 deletion(-)
 rename devices/{ => examples}/HW_device_template.py (100%)

diff --git a/devices/HW_device_template.py b/devices/examples/HW_device_template.py
similarity index 100%
rename from devices/HW_device_template.py
rename to devices/examples/HW_device_template.py
diff --git a/devices/util/hardware_device.py b/devices/util/hardware_device.py
index 9933c1cb8..ce6a9797d 100644
--- a/devices/util/hardware_device.py
+++ b/devices/util/hardware_device.py
@@ -22,7 +22,7 @@ from util.lofar_logging import log_exceptions
 
 __all__ = ["hardware_device"]
 
-from util.wrappers import only_in_states
+from util.wrappers import only_in_states, fault_on_error
 
 
 class hardware_device(Device):
@@ -76,6 +76,8 @@ class hardware_device(Device):
     @command()
     @only_in_states([DevState.FAULT, DevState.OFF])
     @DebugIt()
+    @fault_on_error
+    @log_exceptions()
     def Initialise(self):
         """
         Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
@@ -102,6 +104,8 @@ class hardware_device(Device):
     @command()
     @only_in_states([DevState.STANDBY])
     @DebugIt()
+    @fault_on_error
+    @log_exceptions()
     def On(self):
         """
         Command to ask for initialisation of this device. Can only be called in FAULT or OFF state.
@@ -113,6 +117,7 @@ class hardware_device(Device):
 
     @command()
     @DebugIt()
+    @log_exceptions()
     def Off(self):
         """
         Command to ask for shutdown of this device.
@@ -134,6 +139,7 @@ class hardware_device(Device):
     @command()
     @only_in_states([DevState.ON, DevState.INIT, DevState.STANDBY])
     @DebugIt()
+    @log_exceptions()
     def Fault(self):
         """
         FAULT state is used to indicate our connection with the OPC-UA server is down.
-- 
GitLab