"""This file contains all the classes for handling errors in exceptions that may occur during code execution."""importloggingfromsmia.utilities.fipa_acl_infoimportFIPAACLInfo_logger=logging.getLogger(__name__)
[docs]classCriticalError(Exception):""" This exception class is defined for errors that are critical to the program, so that execution must be terminated. """def__init__(self,message):_logger.error(f"{message}")_logger.error("The program must end.")exit(-1)
[docs]classRequestDataError(Exception):""" This exception class is defined for errors that are related to a request received by the DT (request of a service or a capability). """def__init__(self,message):self.message=message_logger.error(f"{self.message}")
[docs]classAASModelReadingError(Exception):""" This exception class is defined for errors that occur during AAS model management (reading, updating...). """def__init__(self,message,sme_class,reason):self.message=messageself.sme_class=sme_classself.reason=reason_logger.error(f"{self.message}")
[docs]classAASModelOntologyError(Exception):""" This exception class is defined for errors that occur during AAS model management (reading, updating...). """def__init__(self,message,sme_class,reason):self.message=messageself.sme_class=sme_classself.reason=reason_logger.error(f"{self.message}")
# Service management-related exceptions# -------------------------------------
[docs]classServiceRequestExecutionError(Exception):""" This exception class is defined for errors that are related to the execution of a requested service. Since it has been requested, this class also must response to the requester with a Failure of the execution. """def__init__(self,thread,message,behav_class):self.thread=threadself.message=messageself.behav_class=behav_class
[docs]asyncdefhandle_service_execution_error(self):""" This method handles the error during an execution of a service, sending the Failure message to the requester. """_logger.error(f"{self.message}")_logger.info("Due to an incorrect execution of the service related to the thread [{}], the requester shall be ""informed with a Failure message.".format(self.thread))awaitself.behav_class.send_response_msg_to_sender(FIPAACLInfo.FIPA_ACL_PERFORMATIVE_FAILURE,{'reason':self.message})_logger.info("Failure message sent to the requester related to the thread [{}].".format(self.thread))# The behaviour for the execution of the service must be killedself.behav_class.kill(exit_code=10)
[docs]classCapabilityRequestExecutionError(Exception):""" This exception class is defined for errors that are related to the execution of a requested Capability. Since it has been requested, this class also must response to the requester with a Failure of the capability execution. """def__init__(self,cap_name,message,behav_class):self.cap_name=cap_name# TODO pensar si en lugar de nombre de capacidad añadir el thread de la conversacion (quizas es mas identificativo)self.message=messageself.behav_class=behav_class
[docs]asyncdefhandle_capability_execution_error(self):""" This method handles the error during an execution of a capability, sending the Failure message to the requester. """_logger.error(f"{self.message}")_logger.info("Due to an incorrect execution of the capability [{}], the requester shall be informed with a ""Failure message.".format(self.cap_name))awaitself.behav_class.send_response_msg_to_sender(FIPAACLInfo.FIPA_ACL_PERFORMATIVE_FAILURE,{'reason':self.message})_logger.info("Failure message sent to the requester of the capability [{}].".format(self.cap_name))# TODO Pensar si añadir un objeto global en el agente para almacenar informacion sobre errores# The behaviour for the execution of the capability must be killedself.behav_class.kill(exit_code=10)
[docs]classCapabilityCheckingError(Exception):""" This exception class is defined for errors that are related to the execution of the Capability checking process. Since this process is requested by another DT, this class also must response to the requester with a Failure of the capability checking as well as the reason of it. """def__init__(self,cap_name,reason):self.cap_name=cap_nameself.reason=reasonself.behav_class=None
[docs]asyncdefhandle_capability_checking_error(self):""" This method handles the error during an execution of a capability, sending the Failure message to the requester. """_logger.error(f"Capability checking of capability [{self.cap_name}] failed. Reason: {self.reason}")_logger.info("Due to an incorrect checking of a capability, the requester shall be informed with a Failure ""message.")awaitself.behav_class.send_response_msg_to_sender(FIPAACLInfo.FIPA_ACL_PERFORMATIVE_FAILURE,{'message':"Capability checking of capability [{}] failed".format(self.cap_name),'reason':self.reason})_logger.info("Failure message sent to the requester of the capability.")# TODO Pensar si añadir un objeto global en el agente para almacenar informacion sobre errores# The behaviour for the execution of the capability must be killedself.behav_class.kill(exit_code=10)
[docs]classAssetConnectionError(Exception):""" This exception class is defined for errors that are related to the asset connection processes. """def__init__(self,message,error_type,reason):self.message=messageself.error_type=error_typeself.reason=reason_logger.error(f"{self.message}")