From 99e06a679fc9c2d071ab4dc7fa73ceec25254fa0 Mon Sep 17 00:00:00 2001 From: Simon Fayer Date: Tue, 2 Jun 2026 11:40:07 +0100 Subject: [PATCH] fix: Check for ignored broad except --- .../private/Plotters/BaseReporter.py | 4 ++-- .../private/ConfigurationData.py | 8 ++++---- src/DIRAC/Core/Base/AgentModule.py | 8 ++++---- src/DIRAC/Core/Base/CLI.py | 2 +- src/DIRAC/Core/DISET/MessageClient.py | 2 +- src/DIRAC/Core/DISET/ServiceReactor.py | 2 +- src/DIRAC/Core/DISET/private/BaseClient.py | 6 +++--- src/DIRAC/Core/DISET/private/FileHelper.py | 14 +++++++------- .../Core/DISET/private/Transports/BaseTransport.py | 2 +- .../DISET/private/Transports/PlainTransport.py | 2 +- src/DIRAC/Core/Security/ProxyFile.py | 4 ++-- src/DIRAC/Core/Security/VOMS.py | 2 +- src/DIRAC/Core/Tornado/Server/TornadoService.py | 4 ++-- src/DIRAC/Core/Utilities/CGroups2.py | 2 +- src/DIRAC/Core/Utilities/DEncode.py | 4 ++-- src/DIRAC/Core/Utilities/EventDispatcher.py | 2 +- src/DIRAC/Core/Utilities/Graphs/GraphData.py | 8 ++++---- src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py | 6 +++--- src/DIRAC/Core/Utilities/MySQL.py | 14 +++++++------- src/DIRAC/Core/Utilities/Plotting/DataCache.py | 4 ++-- src/DIRAC/Core/Utilities/Subprocess.py | 6 +++--- .../RequestOperations/ReplicateAndRegister.py | 4 ++-- .../DataManagementSystem/Client/FTS3Operation.py | 2 +- .../DirectorySecurityManagerWithDelete.py | 6 +++--- .../scripts/dirac_dms_resolve_guid.py | 7 +------ .../FrameworkSystem/Client/ProxyManagerClient.py | 2 +- .../Service/SystemAdministratorHandler.py | 2 +- .../scripts/dirac_admin_update_instance.py | 14 ++++++++++---- .../FrameworkSystem/scripts/dirac_sys_sendmail.py | 4 ++-- src/DIRAC/Interfaces/Utilities/DCommands.py | 10 ++++++---- src/DIRAC/Interfaces/scripts/dirac_dms_get_file.py | 7 +++++-- .../Interfaces/scripts/dirac_dms_lfn_metadata.py | 7 +++++-- .../Interfaces/scripts/dirac_dms_lfn_replicas.py | 7 +++++-- src/DIRAC/MonitoringSystem/Client/ServerUtils.py | 2 +- .../private/Plotters/BasePlotter.py | 4 ++-- .../scripts/dirac_rms_request.py | 6 +++--- src/DIRAC/Resources/Computing/BatchSystems/Host.py | 2 +- .../Resources/MessageQueue/StompMQConnector.py | 4 ++-- src/DIRAC/Resources/Storage/GFAL2_StorageBase.py | 2 +- .../Agent/TransformationAgent.py | 8 ++++---- .../WorkloadManagementSystem/Client/ServerUtils.py | 2 +- 41 files changed, 110 insertions(+), 98 deletions(-) diff --git a/src/DIRAC/AccountingSystem/private/Plotters/BaseReporter.py b/src/DIRAC/AccountingSystem/private/Plotters/BaseReporter.py index a422e1db8dc..51d9714e8f2 100644 --- a/src/DIRAC/AccountingSystem/private/Plotters/BaseReporter.py +++ b/src/DIRAC/AccountingSystem/private/Plotters/BaseReporter.py @@ -315,12 +315,12 @@ def __checkPlotMetadata(self, metadata): if self._EA_WIDTH in self._extraArgs and self._extraArgs[self._EA_WIDTH]: try: metadata[self._EA_WIDTH] = min(1600, max(200, int(self._extraArgs[self._EA_WIDTH]))) - except Exception: + except (TypeError, ValueError): pass if self._EA_HEIGHT in self._extraArgs and self._extraArgs[self._EA_HEIGHT]: try: metadata[self._EA_HEIGHT] = min(1600, max(200, int(self._extraArgs[self._EA_HEIGHT]))) - except Exception: + except (TypeError, ValueError): pass if self._EA_TITLE in self._extraArgs and self._extraArgs[self._EA_TITLE]: metadata["title"] = self._extraArgs[self._EA_TITLE] diff --git a/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py b/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py index 46b2d524d1a..b21b34ec2f6 100755 --- a/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py +++ b/src/DIRAC/ConfigurationSystem/private/ConfigurationData.py @@ -123,7 +123,7 @@ def getCommentFromCFG(self, path, cfg=False): cfg = cfg[section] return self.dangerZoneEnd(cfg.getComment(levelList[-1])) except Exception: - pass + pass # nosec B110 return self.dangerZoneEnd(None) def getSectionsFromCFG(self, path, cfg=False, ordered=False): @@ -136,7 +136,7 @@ def getSectionsFromCFG(self, path, cfg=False, ordered=False): cfg = cfg[section] return self.dangerZoneEnd(cfg.listSections(ordered)) except Exception: - pass + pass # nosec B110 return self.dangerZoneEnd(None) def getOptionsFromCFG(self, path, cfg=False, ordered=False): @@ -149,7 +149,7 @@ def getOptionsFromCFG(self, path, cfg=False, ordered=False): cfg = cfg[section] return self.dangerZoneEnd(cfg.listOptions(ordered)) except Exception: - pass + pass # nosec B110 return self.dangerZoneEnd(None) def extractOptionFromCFG(self, path, cfg=False, disableDangerZones=False): @@ -164,7 +164,7 @@ def extractOptionFromCFG(self, path, cfg=False, disableDangerZones=False): if levelList[-1] in cfg.listOptions(): return self.dangerZoneEnd(cfg[levelList[-1]]) except Exception: - pass + pass # nosec B110 if not disableDangerZones: self.dangerZoneEnd() diff --git a/src/DIRAC/Core/Base/AgentModule.py b/src/DIRAC/Core/Base/AgentModule.py index 18e0f08187a..8d8d1508848 100644 --- a/src/DIRAC/Core/Base/AgentModule.py +++ b/src/DIRAC/Core/Base/AgentModule.py @@ -234,14 +234,14 @@ def am_createStopAgentFile(self): try: with open(self.am_getStopAgentFile(), "w") as fd: fd.write(f"Dirac site agent Stopped at {str(datetime.datetime.utcnow())}") - except Exception: - pass + except Exception as err: + self.log.info(f"Failed to write stop file: {str(err)}") def am_removeStopAgentFile(self): try: os.unlink(self.am_getStopAgentFile()) - except Exception: - pass + except Exception as err: + self.log.info(f"Failed to remove stop file: {str(err)}") def am_getWorkDirectory(self): return os.path.join(self.__basePath, str(self.am_getOption("WorkDirectory"))) diff --git a/src/DIRAC/Core/Base/CLI.py b/src/DIRAC/Core/Base/CLI.py index fd09243ea5c..9e63688760f 100644 --- a/src/DIRAC/Core/Base/CLI.py +++ b/src/DIRAC/Core/Base/CLI.py @@ -53,7 +53,7 @@ def _initSignals(self): for sigNum in (signal.SIGINT, signal.SIGQUIT, signal.SIGKILL, signal.SIGTERM): try: signal.signal(sigNum, self._handleSignal) - except Exception: + except (ValueError, TypeError, OSError): pass def _errMsg(self, errMsg): diff --git a/src/DIRAC/Core/DISET/MessageClient.py b/src/DIRAC/Core/DISET/MessageClient.py index 03a249de512..56eee51bc6f 100755 --- a/src/DIRAC/Core/DISET/MessageClient.py +++ b/src/DIRAC/Core/DISET/MessageClient.py @@ -90,7 +90,7 @@ def __cbDisconnect(self, trid): try: self.__transport.close() except Exception: - pass + pass # nosec B110 for cb in self.__specialCallbacks["drop"]: try: cb(self) diff --git a/src/DIRAC/Core/DISET/ServiceReactor.py b/src/DIRAC/Core/DISET/ServiceReactor.py index c3f7862be1a..97cc3c9121f 100644 --- a/src/DIRAC/Core/DISET/ServiceReactor.py +++ b/src/DIRAC/Core/DISET/ServiceReactor.py @@ -84,7 +84,7 @@ def closeListeningConnections(self): try: self.__listeningConnections[svcName]["transport"].close() except Exception: - pass + pass # nosec B110 del self.__listeningConnections[svcName]["transport"] gLogger.info("Connections closed") diff --git a/src/DIRAC/Core/DISET/private/BaseClient.py b/src/DIRAC/Core/DISET/private/BaseClient.py index 66cb5206f6a..00528c4fad6 100755 --- a/src/DIRAC/Core/DISET/private/BaseClient.py +++ b/src/DIRAC/Core/DISET/private/BaseClient.py @@ -319,8 +319,8 @@ def __findServiceURL(self): failoverUrlsStr = getServiceFailoverURL(self._destinationSrv) if failoverUrlsStr: failoverUrls = failoverUrlsStr.split(",") - except Exception: - pass + except Exception as err: + gLogger.info(f"Failed to set any failover URLs: {str(err)}") # We randomize the list, and add at the end the failover URLs (System/FailoverURLs/Component) urlsList = List.fromChar(urls, ",") + failoverUrls @@ -608,7 +608,7 @@ def __setKeepAliveLapse(self): if self.KW_KEEP_ALIVE_LAPSE in self.kwargs: try: kaa = max(0, int(self.kwargs[self.KW_KEEP_ALIVE_LAPSE])) - except Exception: + except (ValueError, TypeError): pass if kaa: kaa = max(150, kaa) diff --git a/src/DIRAC/Core/DISET/private/FileHelper.py b/src/DIRAC/Core/DISET/private/FileHelper.py index 7ac965b675c..820f2ff7393 100755 --- a/src/DIRAC/Core/DISET/private/FileHelper.py +++ b/src/DIRAC/Core/DISET/private/FileHelper.py @@ -144,7 +144,7 @@ def networkToFD(self, iFD, maxFileSize=0): try: dataSink.close() except Exception: - pass + pass # nosec B110 def networkToDataSink(self, dataSink, maxFileSize=0): if "write" not in dir(dataSink): @@ -208,7 +208,7 @@ def stringToNetwork(self, stringVal): try: stringIO.close() except Exception: - pass + pass # nosec B110 return S_OK() def FDToNetwork(self, iFD): @@ -323,7 +323,7 @@ def __createTar(self, fileList, wPipe, compress, autoClose=True): try: filePipe.close() except Exception: - pass + pass # nosec B110 def bulkToNetwork(self, fileList, compress=True, onthefly=True): if not onthefly: @@ -341,7 +341,7 @@ def bulkToNetwork(self, fileList, compress=True, onthefly=True): fo.close() os.unlink(filePath) except Exception: - pass + pass # nosec B110 return result else: rPipe, wPipe = os.pipe() @@ -351,7 +351,7 @@ def bulkToNetwork(self, fileList, compress=True, onthefly=True): try: os.close(rPipe) except Exception: - pass + pass # nosec B110 return response def __extractTar(self, destDir, rPipe, compress): @@ -365,14 +365,14 @@ def __extractTar(self, destDir, rPipe, compress): try: filePipe.close() except Exception: - pass + pass # nosec B110 def __receiveToPipe(self, wPipe, retList, maxFileSize): retList.append(self.networkToFD(wPipe, maxFileSize=maxFileSize)) try: os.close(wPipe) except Exception: - pass + pass # nosec B110 def networkToBulk(self, destDir, compress=True, maxFileSize=0): retList = [] diff --git a/src/DIRAC/Core/DISET/private/Transports/BaseTransport.py b/src/DIRAC/Core/DISET/private/Transports/BaseTransport.py index a00a824e2e7..19d81288a2c 100755 --- a/src/DIRAC/Core/DISET/private/Transports/BaseTransport.py +++ b/src/DIRAC/Core/DISET/private/Transports/BaseTransport.py @@ -62,7 +62,7 @@ def __init__(self, stServerAddress, bServerMode=False, **kwargs): if "keepAliveLapse" in kwargs: try: self.__keepAliveLapse = max(150, int(kwargs["keepAliveLapse"])) - except Exception: + except (ValueError, TypeError): pass self.iListenQueueSize = max(self.iListenQueueSize, int(kwargs.get("SocketBacklog", 0))) self.__lastActionTimestamp = time.time() diff --git a/src/DIRAC/Core/DISET/private/Transports/PlainTransport.py b/src/DIRAC/Core/DISET/private/Transports/PlainTransport.py index 7a923a1558a..305f09359a8 100755 --- a/src/DIRAC/Core/DISET/private/Transports/PlainTransport.py +++ b/src/DIRAC/Core/DISET/private/Transports/PlainTransport.py @@ -49,7 +49,7 @@ def close(self): try: self.oSocket.shutdown(socket.SHUT_RDWR) except Exception: - pass + pass # nosec B110 self.oSocket.close() def setClientSocket(self, oSocket): diff --git a/src/DIRAC/Core/Security/ProxyFile.py b/src/DIRAC/Core/Security/ProxyFile.py index d5218f00734..0f6a2bd4b2d 100644 --- a/src/DIRAC/Core/Security/ProxyFile.py +++ b/src/DIRAC/Core/Security/ProxyFile.py @@ -67,7 +67,7 @@ def writeChainToTemporaryFile(proxyChain): if not retVal["OK"]: try: os.unlink(proxyLocation) - except Exception: + except OSError: pass return retVal return S_OK(proxyLocation) @@ -80,7 +80,7 @@ def deleteMultiProxy(multiProxyDict): if multiProxyDict["tempFile"]: try: os.unlink(multiProxyDict["file"]) - except Exception: + except OSError: pass diff --git a/src/DIRAC/Core/Security/VOMS.py b/src/DIRAC/Core/Security/VOMS.py index 578bd7f1536..124eead522a 100644 --- a/src/DIRAC/Core/Security/VOMS.py +++ b/src/DIRAC/Core/Security/VOMS.py @@ -328,7 +328,7 @@ def _unlinkFiles(self, files): else: try: os.unlink(files) - except Exception: + except OSError: pass def _generateTemporalFile(self): diff --git a/src/DIRAC/Core/Tornado/Server/TornadoService.py b/src/DIRAC/Core/Tornado/Server/TornadoService.py index 69a921553f3..dc4bd80bfd7 100644 --- a/src/DIRAC/Core/Tornado/Server/TornadoService.py +++ b/src/DIRAC/Core/Tornado/Server/TornadoService.py @@ -189,7 +189,7 @@ def export_ping(self): iUptime = int(float(oFD.readline().split()[0].strip())) dInfo["host uptime"] = iUptime except Exception: # pylint: disable=broad-except - pass + pass # nosec B110 startTime = self._startTime dInfo["service start time"] = self._startTime serviceUptime = datetime.utcnow() - startTime @@ -199,7 +199,7 @@ def export_ping(self): with open("/proc/loadavg") as oFD: dInfo["load"] = " ".join(oFD.read().split()[:3]) except Exception: # pylint: disable=broad-except - pass + pass # nosec B110 dInfo["name"] = self._serviceInfoDict["serviceName"] dInfo["URL"] = self._serviceInfoDict["URL"] stTimes = os.times() diff --git a/src/DIRAC/Core/Utilities/CGroups2.py b/src/DIRAC/Core/Utilities/CGroups2.py index f7cb460f572..bcd014c5d45 100644 --- a/src/DIRAC/Core/Utilities/CGroups2.py +++ b/src/DIRAC/Core/Utilities/CGroups2.py @@ -267,7 +267,7 @@ def _setup_subproc(self, slot_name): except Exception as err: # We can't even really log here as we're in the set-up # context of the new proces - pass + pass # nosec B110 def setUp(self): """Creates the base cgroup tree if possible. Should be called once diff --git a/src/DIRAC/Core/Utilities/DEncode.py b/src/DIRAC/Core/Utilities/DEncode.py index bae1a2179c1..1f79247f6a5 100755 --- a/src/DIRAC/Core/Utilities/DEncode.py +++ b/src/DIRAC/Core/Utilities/DEncode.py @@ -207,8 +207,8 @@ def stripArgs(frame): print("With arguments ", end=" ") pprint(dencArgs) break - except Exception: - pass + except Exception as err: + print(f"Failed to trace frames: {str(err)}") print("=" * 100) print() print() diff --git a/src/DIRAC/Core/Utilities/EventDispatcher.py b/src/DIRAC/Core/Utilities/EventDispatcher.py index 297fd29da97..c206e4990c4 100644 --- a/src/DIRAC/Core/Utilities/EventDispatcher.py +++ b/src/DIRAC/Core/Utilities/EventDispatcher.py @@ -84,7 +84,7 @@ def __realTrigger(self, eventName, params): try: gEventSync.unlock() except Exception: - pass + pass # nosec B110 if not finalResult["OK"]: return finalResult return S_OK(len(eventFunctors)) diff --git a/src/DIRAC/Core/Utilities/Graphs/GraphData.py b/src/DIRAC/Core/Utilities/Graphs/GraphData.py index 1da85794853..0602b78ca11 100644 --- a/src/DIRAC/Core/Utilities/Graphs/GraphData.py +++ b/src/DIRAC/Core/Utilities/Graphs/GraphData.py @@ -332,25 +332,25 @@ def getStatString(self, unit=None): s = "Max: " + pretty_float(max_value) + " " + unitString tmpList.append(s.strip()) except Exception: - pass + pass # nosec B110 if min_value: try: s = "Min: " + pretty_float(min_value) + " " + unitString tmpList.append(s.strip()) except Exception: - pass + pass # nosec B110 if average: try: s = "Average: " + pretty_float(average) + " " + unitString tmpList.append(s.strip()) except Exception: - pass + pass # nosec B110 if current: try: s = "Current: " + pretty_float(current) + " " + unitString tmpList.append(s.strip()) except Exception: - pass + pass # nosec B110 resultString = ", ".join(tmpList) return resultString diff --git a/src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py b/src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py index 1d154c7f33e..8cb734b7f2b 100644 --- a/src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py +++ b/src/DIRAC/Core/Utilities/Graphs/GraphUtilities.py @@ -91,7 +91,7 @@ def convert_to_datetime(dstring): results = datetime.datetime.utcfromtimestamp(timestamp) break except Exception: - pass + pass # nosec B110 if t is None: try: dstring = dstring.split(".", 1)[0] @@ -109,10 +109,10 @@ def convert_to_datetime(dstring): def to_timestamp(val): try: v = float(val) - if v > 1000000000 and v < 1900000000: + if v > 1000000000 and v < 2540000000: return v except Exception: - pass + pass # nosec B110 val = convert_to_datetime(val) return calendar.timegm(val.timetuple()) diff --git a/src/DIRAC/Core/Utilities/MySQL.py b/src/DIRAC/Core/Utilities/MySQL.py index 683d25f4251..6e02441df5a 100755 --- a/src/DIRAC/Core/Utilities/MySQL.py +++ b/src/DIRAC/Core/Utilities/MySQL.py @@ -439,7 +439,7 @@ def discardCurrentThreadConn(self): try: data[0].close() except Exception: - pass + pass # nosec B110 def __pop(self, thid): try: @@ -545,7 +545,7 @@ def __del__(self): try: gInstancesCount -= 1 except Exception: - pass + pass # nosec B110 # MySQLdb error codes that mean the connection itself is dead and must be discarded. __CONNECTION_LOST_ERRNOS = frozenset((2006, 2013, 2055, 4031)) @@ -769,7 +769,7 @@ def _query(self, cmd, *, args=None, conn=None, debug=True): try: cursor.close() except Exception: - pass + pass # nosec B110 return retDict @@ -809,7 +809,7 @@ def _update(self, cmd, *, args=None, conn=None, debug=True): try: cursor.close() except Exception: - pass + pass # nosec B110 return retDict @@ -844,7 +844,7 @@ def _updatemany(self, cmd, data, *, conn=None, debug=True): try: cursor.close() except Exception: - pass + pass # nosec B110 return retDict @@ -1716,7 +1716,7 @@ def executeStoredProcedure(self, packageName, parameters, outputIds, *, conn=Non try: cursor.close() except Exception: - pass + pass # nosec B110 return retDict # For the procedures that execute a select without storing the result @@ -1747,6 +1747,6 @@ def executeStoredProcedureWithCursor(self, packageName, parameters, *, conn=None try: cursor.close() except Exception: - pass + pass # nosec B110 return retDict diff --git a/src/DIRAC/Core/Utilities/Plotting/DataCache.py b/src/DIRAC/Core/Utilities/Plotting/DataCache.py index efc2b841e52..7d010b9e813 100644 --- a/src/DIRAC/Core/Utilities/Plotting/DataCache.py +++ b/src/DIRAC/Core/Utilities/Plotting/DataCache.py @@ -87,5 +87,5 @@ def _deleteGraph(self, plotDict): os.unlink(fPath) else: gLogger.info("Plot has already been deleted", value) - except Exception: - pass + except Exception as err: + gLogger.warn(f"Error while deleting plot! {str(err)}") diff --git a/src/DIRAC/Core/Utilities/Subprocess.py b/src/DIRAC/Core/Utilities/Subprocess.py index 6e858a6aa9e..434e99c0bc3 100644 --- a/src/DIRAC/Core/Utilities/Subprocess.py +++ b/src/DIRAC/Core/Utilities/Subprocess.py @@ -403,7 +403,7 @@ def __readFromFile(self, fd, baseLength): self.log.error("Error reading", f"type(nB) ={type(nB)}") self.log.error("Error reading", f"nB ={str(nB)}") except Exception: - pass + pass # nosec B110 return S_ERROR(f"Can not read from output: {str(x)}") if len(dataString) + baseLength > self.bufferLimit: self.log.error("Maximum output buffer length reached") @@ -464,7 +464,7 @@ def systemCall( self.child.stdout.close() self.child.stderr.close() except Exception: - pass + pass # nosec B110 retDict = S_ERROR(repr(x)) retDict["Value"] = (-1, "", str(x)) return retDict @@ -502,7 +502,7 @@ def systemCall( self.child.stdout.close() self.child.stderr.close() except Exception: - pass + pass # nosec B110 def getChildPID(self): """child pid getter""" diff --git a/src/DIRAC/DataManagementSystem/Agent/RequestOperations/ReplicateAndRegister.py b/src/DIRAC/DataManagementSystem/Agent/RequestOperations/ReplicateAndRegister.py index 062fe7181e2..2426634a1fa 100644 --- a/src/DIRAC/DataManagementSystem/Agent/RequestOperations/ReplicateAndRegister.py +++ b/src/DIRAC/DataManagementSystem/Agent/RequestOperations/ReplicateAndRegister.py @@ -477,8 +477,8 @@ def fts3Transfer(self): vo = getVOfromProxyGroup().get("Value") fts3Plugin = getFTS3Plugin(vo=vo) fts3Operation.activity = fts3Plugin.inferFTSActivity(fts3Operation, self.request, self.operation) - except Exception: - pass + except Exception as err: + self.log.warn(f"Failed to infer FTS3 activity: {str(err)}") ftsSchedule = FTS3Client().persistOperation(fts3Operation) if not ftsSchedule["OK"]: diff --git a/src/DIRAC/DataManagementSystem/Client/FTS3Operation.py b/src/DIRAC/DataManagementSystem/Client/FTS3Operation.py index 67b7042bd09..763b5b4f994 100644 --- a/src/DIRAC/DataManagementSystem/Client/FTS3Operation.py +++ b/src/DIRAC/DataManagementSystem/Client/FTS3Operation.py @@ -388,7 +388,7 @@ def fromRMSObjects(cls, rmsReq, rmsOp): ftsOp.activity = argumentDic["activity"] ftsOp.priority = argumentDic["priority"] except Exception: - pass + pass # nosec B110 return ftsOp diff --git a/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/SecurityManager/DirectorySecurityManagerWithDelete.py b/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/SecurityManager/DirectorySecurityManagerWithDelete.py index 2becaf53e27..a2e0521a297 100644 --- a/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/SecurityManager/DirectorySecurityManagerWithDelete.py +++ b/src/DIRAC/DataManagementSystem/DB/FileCatalogComponents/SecurityManager/DirectorySecurityManagerWithDelete.py @@ -68,11 +68,11 @@ def getPathPermissions(self, paths, credDict): # The try catch is just to protect in case there are duplicate in the paths try: paths.remove(path) - except Exception as _e: + except Exception: try: paths.pop(path) - except Exception as _ee: - pass + except Exception: + pass # nosec B110 # For all the paths that exist, check the write permission if paths: diff --git a/src/DIRAC/DataManagementSystem/scripts/dirac_dms_resolve_guid.py b/src/DIRAC/DataManagementSystem/scripts/dirac_dms_resolve_guid.py index 963b84afa3a..b914d97b21b 100755 --- a/src/DIRAC/DataManagementSystem/scripts/dirac_dms_resolve_guid.py +++ b/src/DIRAC/DataManagementSystem/scripts/dirac_dms_resolve_guid.py @@ -16,12 +16,7 @@ def main(): # parseCommandLine show help when mandatory arguments are not specified or incorrect argument args = Script.getPositionalArgs() - guids = args[0] - - try: - guids = guids.split(",") - except Exception: - pass + guids = args[0].split(",") from DIRAC.Resources.Catalog.FileCatalog import FileCatalog diff --git a/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py b/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py index cc435685ef8..14883429b3b 100755 --- a/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py +++ b/src/DIRAC/FrameworkSystem/Client/ProxyManagerClient.py @@ -40,7 +40,7 @@ def __deleteTemporalFile(filename): """ try: os.remove(filename) - except Exception: + except OSError: pass def clearCaches(self): diff --git a/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py b/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py index 12808097d6e..06f91c98f8c 100644 --- a/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py +++ b/src/DIRAC/FrameworkSystem/Service/SystemAdministratorHandler.py @@ -704,7 +704,7 @@ def export_getComponentDocumentation(self, cType, system, module): importedModule = importlib.import_module(moduleName) return S_OK(importedModule.__doc__) except Exception: - pass + continue # Module or doc string missing, keep searching return S_ERROR("No documentation was found") @staticmethod diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_update_instance.py b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_update_instance.py index b8f15aa44b5..e19d6735118 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_admin_update_instance.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_admin_update_instance.py @@ -45,8 +45,11 @@ def main(): with open(hosts) as f: hosts = f.read().splitlines() hosts = [str(host) for host in hosts] - except Exception: - pass + except FileNotFoundError: + pass # The user probably supplied one of most hosts directly + except Exception as err: + print(f"ERROR: Failed to read host list file {hosts}: {str(err)}") + DIRAC.exit(1) if not isinstance(hosts, list): hosts = hosts.split(",") @@ -56,8 +59,11 @@ def main(): with open(excludeHosts) as f: excludeHosts = f.read().splitlines() excludeHosts = [str(host) for host in excludeHosts] - except Exception: - pass + except FileNotFoundError: + pass # The user probably supplied one of most hosts directly + except Exception as err: + print(f"ERROR: Failed to read excluded host list file {hosts}: {str(err)}") + DIRAC.exit(1) if not isinstance(excludeHosts, list): excludeHosts = excludeHosts.split(",") diff --git a/src/DIRAC/FrameworkSystem/scripts/dirac_sys_sendmail.py b/src/DIRAC/FrameworkSystem/scripts/dirac_sys_sendmail.py index 1c4af53ef4f..099f21a150b 100755 --- a/src/DIRAC/FrameworkSystem/scripts/dirac_sys_sendmail.py +++ b/src/DIRAC/FrameworkSystem/scripts/dirac_sys_sendmail.py @@ -46,8 +46,8 @@ def main(): try: tmp, body = body.split("\\n\\n") head = tmp + "\\n" + head - except Exception as x: - pass + except ValueError as x: + pass # Double new-line not found body = "".join(body.strip()) diff --git a/src/DIRAC/Interfaces/Utilities/DCommands.py b/src/DIRAC/Interfaces/Utilities/DCommands.py index 3c58ff00e9e..e5ac23001a0 100644 --- a/src/DIRAC/Interfaces/Utilities/DCommands.py +++ b/src/DIRAC/Interfaces/Utilities/DCommands.py @@ -518,9 +518,11 @@ def proxyInit(self): try: self.addVomsExt(filename) - except: - # silently skip VOMS errors - pass + except KeyError: + pass # No VOMS server for this group + except Exception as err: + # Another problem getting VOMS ext + gLogger.warn(f"Failed to add VOMS extension: ({str(err)})") if not (result := addTokenToPEM(filename, params.diracGroup))["OK"]: # pylint: disable=unsubscriptable-object raise Exception(result["Message"]) # pylint: disable=unsubscriptable-object @@ -533,7 +535,7 @@ def addVomsExt(self, proxy): group = retVal["Value"] vomsAttr = Registry.getVOMSAttributeForGroup(group) if not vomsAttr: - raise Exception(f"Requested adding a VOMS extension but no VOMS attribute defined for group {group}") + raise KeyError(f"Requested adding a VOMS extension but no VOMS attribute defined for group {group}") result = VOMS.VOMS().setVOMSAttributes(proxy, attribute=vomsAttr, vo=Registry.getVOForGroup(group)) if not result["OK"]: diff --git a/src/DIRAC/Interfaces/scripts/dirac_dms_get_file.py b/src/DIRAC/Interfaces/scripts/dirac_dms_get_file.py index 3b681c269ab..965297c9d9b 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_dms_get_file.py +++ b/src/DIRAC/Interfaces/scripts/dirac_dms_get_file.py @@ -34,8 +34,11 @@ def main(): try: with open(lfns[0]) as f: lfns = f.read().splitlines() - except Exception: - pass + except FileNotFoundError: + pass # The user probably supplied an LFN not a local file name + except Exception as err: + print(f"ERROR: Failed to read LFN list file {lfns[0]}: {str(err)}") + DIRAC.exit(1) result = dirac.getFile(lfns, printOutput=True) if not result["OK"]: diff --git a/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_metadata.py b/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_metadata.py index 1f040050a7c..629a188ba20 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_metadata.py +++ b/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_metadata.py @@ -42,8 +42,11 @@ def main(): try: with open(lfns[0]) as f: lfns = f.read().splitlines() - except Exception: - pass + except FileNotFoundError: + pass # The user probably supplied an LFN not a local file name + except Exception as err: + print(f"ERROR: Failed to read LFN list file {lfns[0]}: {str(err)}") + DIRAC.exit(1) result = dirac.getLfnMetadata(lfns, printOutput=True) if not result["OK"]: diff --git a/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_replicas.py b/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_replicas.py index ba8ef932e62..79e33cc9a6f 100755 --- a/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_replicas.py +++ b/src/DIRAC/Interfaces/scripts/dirac_dms_lfn_replicas.py @@ -38,8 +38,11 @@ def main(): try: with open(lfns[0]) as f: lfns = f.read().splitlines() - except Exception: - pass + except FileNotFoundError: + pass # The user probably supplied an LFN not a local file name + except Exception as err: + print(f"ERROR: Failed to read LFN list file {lfns[0]}: {str(err)}") + DIRAC.exit(1) result = dirac.getReplicas(lfns, active=active, printOutput=True) if not result["OK"]: diff --git a/src/DIRAC/MonitoringSystem/Client/ServerUtils.py b/src/DIRAC/MonitoringSystem/Client/ServerUtils.py index e762f1a82a5..6e51ff1ba74 100644 --- a/src/DIRAC/MonitoringSystem/Client/ServerUtils.py +++ b/src/DIRAC/MonitoringSystem/Client/ServerUtils.py @@ -11,7 +11,7 @@ def getMonitoringDB(): if gMonitoringDB and gMonitoringDB._connected: return gMonitoringDB except Exception: - pass + pass # nosec B110 from DIRAC.Core.Base.Client import Client diff --git a/src/DIRAC/MonitoringSystem/private/Plotters/BasePlotter.py b/src/DIRAC/MonitoringSystem/private/Plotters/BasePlotter.py index 90a5fa30773..cf5ac6d5208 100644 --- a/src/DIRAC/MonitoringSystem/private/Plotters/BasePlotter.py +++ b/src/DIRAC/MonitoringSystem/private/Plotters/BasePlotter.py @@ -308,12 +308,12 @@ def __checkPlotMetadata(self, metadata): if self._extraArgs.get(self._EA_WIDTH): try: metadata[self._EA_WIDTH] = min(1600, max(200, int(self._extraArgs[self._EA_WIDTH]))) - except Exception: + except (TypeError, ValueError): pass if self._EA_HEIGHT in self._extraArgs and self._extraArgs[self._EA_HEIGHT]: try: metadata[self._EA_HEIGHT] = min(1600, max(200, int(self._extraArgs[self._EA_HEIGHT]))) - except Exception: + except (TypeError, ValueError): pass if self._extraArgs.get(self._EA_TITLE): metadata["title"] = self._extraArgs[self._EA_TITLE] diff --git a/src/DIRAC/RequestManagementSystem/scripts/dirac_rms_request.py b/src/DIRAC/RequestManagementSystem/scripts/dirac_rms_request.py index 705aea43a72..8e6c8e39190 100755 --- a/src/DIRAC/RequestManagementSystem/scripts/dirac_rms_request.py +++ b/src/DIRAC/RequestManagementSystem/scripts/dirac_rms_request.py @@ -12,7 +12,7 @@ def convertDate(date): try: value = datetime.datetime.strptime(date, "%Y-%m-%d") return value - except Exception: + except (ValueError, TypeError): pass try: value = datetime.datetime.utcnow() - datetime.timedelta(hours=int(24 * float(date))) @@ -138,8 +138,8 @@ def main(): elif switch[0] == "Maximum": try: maxRequests = int(switch[1]) - except Exception: - pass + except ValueError: + gLogger.fatal(f"Invalid maximum value: {switch[1]}") elif switch[0] == "TargetSE": targetSE = set(switch[1].split(",")) diff --git a/src/DIRAC/Resources/Computing/BatchSystems/Host.py b/src/DIRAC/Resources/Computing/BatchSystems/Host.py index cdd0a49396b..ad59bb7dea2 100644 --- a/src/DIRAC/Resources/Computing/BatchSystems/Host.py +++ b/src/DIRAC/Resources/Computing/BatchSystems/Host.py @@ -32,7 +32,7 @@ def __init__(self): try: self.nCores = multiprocessing.cpu_count() except Exception: - pass + pass # nosec B110 def submitJob(self, **kwargs): diff --git a/src/DIRAC/Resources/MessageQueue/StompMQConnector.py b/src/DIRAC/Resources/MessageQueue/StompMQConnector.py index 93155644511..6bae7effa30 100644 --- a/src/DIRAC/Resources/MessageQueue/StompMQConnector.py +++ b/src/DIRAC/Resources/MessageQueue/StompMQConnector.py @@ -206,8 +206,8 @@ def connect(self, parameters=None): # Go to the socket of the Stomp to find the remote host try: remoteIP = self.connection.transport.socket.getpeername()[0] - except Exception: - pass + except Exception as err: + log.info(f"MQ failed to get peer name: {str(err)}") log.info(f"MQ Connected to {remoteIP}") return S_OK(f"Connected to {remoteIP}") else: diff --git a/src/DIRAC/Resources/Storage/GFAL2_StorageBase.py b/src/DIRAC/Resources/Storage/GFAL2_StorageBase.py index f1137048330..5f62e144e15 100644 --- a/src/DIRAC/Resources/Storage/GFAL2_StorageBase.py +++ b/src/DIRAC/Resources/Storage/GFAL2_StorageBase.py @@ -519,7 +519,7 @@ def _getSingleFile(self, src_url: str, dest_file: str, disableChecksum: bool = F try: os.remove(dest_file) except Exception: - pass + log.debug(f"Failed to remove file {dest_file}") raise RuntimeError(f"Remote and local filesizes don't match: {sourceSize} vs {localSize}") @convertToReturnValue diff --git a/src/DIRAC/TransformationSystem/Agent/TransformationAgent.py b/src/DIRAC/TransformationSystem/Agent/TransformationAgent.py index 1339452b09a..bd4d0425002 100644 --- a/src/DIRAC/TransformationSystem/Agent/TransformationAgent.py +++ b/src/DIRAC/TransformationSystem/Agent/TransformationAgent.py @@ -469,8 +469,8 @@ def __getDataReplicas(self, transDict, lfns, clients, forJobs=True): clearCache = os.path.exists(clearCacheFile) if clearCache: os.remove(clearCacheFile) - except Exception: - pass + except Exception as err: + self._logWarn(f"Failed to clear cache file {clearCacheFile}: {srt(err)}", method=method, transID=transID) if clearCache or transDict["Status"] == "Flush": self._logInfo("Replica cache cleared", method=method, transID=transID) # We may need to get new replicas @@ -748,5 +748,5 @@ def pluginCallback(self, transID, invalidateCache=False): ) self.replicaCache.pop(transID) self.__writeCache(transID) - except Exception: - pass + except Exception as err: + self._logWarn(f"Failed to invalidate cache: {str(err)}", method="pluginCallBack", transID=transID) diff --git a/src/DIRAC/WorkloadManagementSystem/Client/ServerUtils.py b/src/DIRAC/WorkloadManagementSystem/Client/ServerUtils.py index 3a2e99be94c..206372e444b 100644 --- a/src/DIRAC/WorkloadManagementSystem/Client/ServerUtils.py +++ b/src/DIRAC/WorkloadManagementSystem/Client/ServerUtils.py @@ -13,6 +13,6 @@ def getPilotAgentsDB(): if gPilotAgentsDB and gPilotAgentsDB._connected: return gPilotAgentsDB except Exception: - pass + pass # nosec B110 return Client(url="WorkloadManagement/PilotManager")