diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 8653285dc8b542c65076e3918e27ee40cce9847e..1895cd82b4349d982054706922f34499977a9893 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -4798,7 +4798,7 @@ class Autosubmit: raise AutosubmitError(e.message, e.code, e.trace) except AutosubmitCritical as e: # TODO: == "" or is None? - if e.trace == "": + if e.trace == "" or not e.trace: e.trace = traceback.format_exc() raise AutosubmitCritical(e.message, e.code, e.trace) except BaseException as e: diff --git a/autosubmit/job/job_list.py b/autosubmit/job/job_list.py index eca3aa9ca330e08a837bbbeaa83eb574b1970e71..6e924f1093603d0ca4a2309895f1ca7e0b8adda9 100644 --- a/autosubmit/job/job_list.py +++ b/autosubmit/job/job_list.py @@ -207,6 +207,8 @@ class JobList(object): self.graph = self.load() if type(self.graph) is not DiGraph: self.graph = nx.DiGraph() + except AutosubmitCritical: + raise except: self.graph = nx.DiGraph() self._dic_jobs = DicJobs(date_list, member_list, chunk_list, date_format, default_retrials, as_conf) @@ -2322,6 +2324,8 @@ class JobList(object): Log.info("Loading JobList") try: return self._persistence.load(self._persistence_path, self._persistence_file) + except AutosubmitCritical: + raise except: Log.printlog( "Autosubmit will use a backup for recover the job_list", 6010) diff --git a/autosubmit/job/job_list_persistence.py b/autosubmit/job/job_list_persistence.py index bb884ba439ef5cde85ff6b3d25e7710236fb4acd..951771bed1523e908eb32efedfa784544d130cde 100644 --- a/autosubmit/job/job_list_persistence.py +++ b/autosubmit/job/job_list_persistence.py @@ -21,7 +21,7 @@ import pickle from sys import setrecursionlimit import shutil from autosubmit.database.db_manager import DbManager -from log.log import Log +from log.log import AutosubmitCritical, Log class JobListPersistence(object): @@ -66,7 +66,14 @@ class JobListPersistencePkl(JobListPersistence): """ path = os.path.join(persistence_path, persistence_file + '.pkl') - if os.path.exists(path): + try: + open(path).close() + except PermissionError: + raise AutosubmitCritical(f'Permission denied to read {path}', 7012) + except FileNotFoundError: + Log.printlog(f'File {path} does not exist. ',Log.WARNING) + return list() + else: # copy the path to a tmp file randomseed to avoid corruption path_tmp = f'{path}.tmp_{os.urandom(8).hex()}' shutil.copy(path, path_tmp) @@ -82,9 +89,6 @@ class JobListPersistencePkl(JobListPersistence): graph.nodes[u]["job"]._serial_platform = None graph.nodes[u]["job"].submitter = None return graph - else: - Log.printlog('File {0} does not exist'.format(path),Log.WARNING) - return list() def save(self, persistence_path, persistence_file, job_list, graph): """ diff --git a/bin/autosubmit b/bin/autosubmit index 4280dc71ef5677d3c4b2b70d2679ed389af56618..21c056019acadd564af7329d6ea315a0a6a1949e 100755 --- a/bin/autosubmit +++ b/bin/autosubmit @@ -22,6 +22,7 @@ import os import sys import traceback from io import StringIO # for handling the traceback print +from contextlib import suppress scriptdir = os.path.abspath(os.path.dirname(sys.argv[0])) sys.path.append(scriptdir) @@ -31,6 +32,18 @@ from log.log import Log, AutosubmitCritical , AutosubmitError from autosubmit.autosubmit import Autosubmit +def exit_from_error(e): + with suppress(FileNotFoundError, PermissionError): + os.remove(os.path.join(Log.file_path, "autosubmit.lock")) + try: + if not e.trace: + Log.debug("Trace: {0}", str(e.trace)) + Log.critical("{1} [eCode={0}]", e.code, e.message) + except: + Log.critical("An Unknown error occurred: {0}.\n Please report it to Autosubmit Developers through Git", str(e)) + Log.info("More info at https://autosubmit.readthedocs.io/en/master/troubleshooting/error-codes.html") + os._exit(1) + # noinspection PyProtectedMember def main(): try: @@ -41,37 +54,11 @@ def main(): os._exit(return_value) os._exit(0) except AutosubmitError as e: - if os.path.exists(os.path.join(Log.file_path, "autosubmit.lock")): - os.remove(os.path.join(Log.file_path, "autosubmit.lock")) - if e.trace is not None: - if e.trace != "": # trace might be int. - Log.error("Trace: {0}", e.trace) - Log.critical("{1} [eCode={0}]", e.code, e.message) - Log.info("More info at https://autosubmit.readthedocs.io/en/master/troubleshooting/error-codes.html") - os._exit(1) + exit_from_error(e) except AutosubmitCritical as e: - if os.path.exists(os.path.join(Log.file_path, "autosubmit.lock")): - os.remove(os.path.join(Log.file_path, "autosubmit.lock")) - str(traceback.print_exc()) - if e.trace is not None or e.trace == "": - Log.error("Trace: {0}", e.trace) - Log.critical("{1} [eCode={0}]", e.code, e.message) - - Log.info("More info at https://autosubmit.readthedocs.io/en/master/troubleshooting/error-codes.html") - os._exit(1) - except Exception as e: - if os.path.exists(os.path.join(Log.file_path, "autosubmit.lock")): - os.remove(os.path.join(Log.file_path, "autosubmit.lock")) - Log.error("Trace: {0}", str(e)) - if "temporarily unavailable" in str(e): - Log.critical( - "{0}\nAnother instance of autosubmit is running on this experiment. If this is not the case, delete autosubmit.lock".format(str(e)), 7000) - else: - exception_stream = StringIO() - traceback.print_exc(file=exception_stream) - raise AutosubmitCritical("Unhandled error: If you see this message, please report it in Autosubmit's GitLab project", 7000, str(e)) - os._exit(1) - + exit_from_error(e) + except BaseException as e: + exit_from_error(e) if __name__ == "__main__": main()