From 26d731c8fd1f476b76ba83c66dac018c4d6f8584 Mon Sep 17 00:00:00 2001 From: Romain Baville Date: Thu, 19 Feb 2026 15:22:29 +0100 Subject: [PATCH 1/6] Add an error counter to stop geomechanics workflow --- .../post_processing/GeomechanicsCalculator.py | 5 + .../PVGeomechanicsCalculator.py | 97 +++++++++++-------- .../post_processing/PVGeomechanicsWorkflow.py | 11 ++- geos-utils/src/geos/utils/Logger.py | 23 ++++- 4 files changed, 93 insertions(+), 43 deletions(-) diff --git a/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py b/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py index 8b902092..545498fc 100644 --- a/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py +++ b/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py @@ -715,9 +715,11 @@ def __init__( counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -771,6 +773,9 @@ def applyFilter( self: Self ) -> None: self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return def getOutput( self: Self ) -> vtkUnstructuredGrid: diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py index 693a5f5f..bbeb98bc 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py @@ -102,9 +102,11 @@ def __init__( self: Self ) -> None: counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -282,57 +284,70 @@ def ApplyFilter( except ( ValueError, AttributeError ) as e: geomechanicsCalculatorFilter.logger.error( f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" ) + self.counter.addExternalErrorCount( geomechanicsCalculatorFilter.nbErrors ) except Exception as e: mess = f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" geomechanicsCalculatorFilter.logger.critical( mess, exc_info=True ) + self.counter.addExternalErrorCount( geomechanicsCalculatorFilter.nbErrors ) elif isinstance( outputMesh, vtkMultiBlockDataSet ): self.logger.info( f"Apply plugin { self.logger.name }." ) - volumeBlockIndexes: list[ int ] = getBlockElementIndexesFlatten( outputMesh ) - for blockIndex in volumeBlockIndexes: - volumeBlock: vtkUnstructuredGrid = vtkUnstructuredGrid.SafeDownCast( - outputMesh.GetDataSet( blockIndex ) ) - volumeBlockName: str = getBlockNameFromIndex( outputMesh, blockIndex ) - filterName: str = f"Geomechanics Calculator for the block { volumeBlockName }" - - geomechanicsCalculatorFilter = GeomechanicsCalculator( - volumeBlock, - self.computeAdvancedProperties, - filterName, - True, - ) - - if not isHandlerInLogger( self.handler, geomechanicsCalculatorFilter.logger ): - geomechanicsCalculatorFilter.setLoggerHandler( self.handler ) - - geomechanicsCalculatorFilter.physicalConstants.grainBulkModulus = self.grainBulkModulus - geomechanicsCalculatorFilter.physicalConstants.specificDensity = self.specificDensity - geomechanicsCalculatorFilter.physicalConstants.rockCohesion = self.rockCohesion - geomechanicsCalculatorFilter.physicalConstants.frictionAngle = self.frictionAngle - - try: - geomechanicsCalculatorFilter.applyFilter() - # Add to the warning counter the number of warning logged with the call of GeomechanicsCalculator filter - self.counter.addExternalWarningCount( geomechanicsCalculatorFilter.nbWarnings ) - - volumeBlock.ShallowCopy( geomechanicsCalculatorFilter.getOutput() ) - volumeBlock.Modified() - except ( ValueError, AttributeError ) as e: - geomechanicsCalculatorFilter.logger.error( - f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" ) - except Exception as e: - mess = f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" - geomechanicsCalculatorFilter.logger.critical( mess, exc_info=True ) - - result: str = f"The filter { self.logger.name } succeeded" - if self.counter.warningCount > 0: - self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." ) - else: - self.logger.info( f"{ result }." ) + try: + volumeBlockIndexes: list[ int ] = getBlockElementIndexesFlatten( outputMesh ) + for blockIndex in volumeBlockIndexes: + volumeBlock: vtkUnstructuredGrid = vtkUnstructuredGrid.SafeDownCast( + outputMesh.GetDataSet( blockIndex ) ) + volumeBlockName: str = getBlockNameFromIndex( outputMesh, blockIndex ) + filterName: str = f"Geomechanics Calculator for the block { volumeBlockName }" + + geomechanicsCalculatorFilter = GeomechanicsCalculator( + volumeBlock, + self.computeAdvancedProperties, + filterName, + True, + ) + + if not isHandlerInLogger( self.handler, geomechanicsCalculatorFilter.logger ): + geomechanicsCalculatorFilter.setLoggerHandler( self.handler ) + + geomechanicsCalculatorFilter.physicalConstants.grainBulkModulus = self.grainBulkModulus + geomechanicsCalculatorFilter.physicalConstants.specificDensity = self.specificDensity + geomechanicsCalculatorFilter.physicalConstants.rockCohesion = self.rockCohesion + geomechanicsCalculatorFilter.physicalConstants.frictionAngle = self.frictionAngle + + try: + geomechanicsCalculatorFilter.applyFilter() + # Add to the warning counter the number of warning logged with the call of GeomechanicsCalculator filter + self.counter.addExternalWarningCount( geomechanicsCalculatorFilter.nbWarnings ) + + volumeBlock.ShallowCopy( geomechanicsCalculatorFilter.getOutput() ) + volumeBlock.Modified() + except ( ValueError, AttributeError ) as e: + geomechanicsCalculatorFilter.logger.error( f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" ) + raise ChildProcessError( f"Error during the processing of: { filterName }." ) + except Exception as e: + mess = f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" + geomechanicsCalculatorFilter.logger.critical( mess, exc_info=True ) + raise ChildProcessError( f"Critical error during the processing of: { filterName }." ) + + result: str = f"The plugin { self.logger.name } succeeded" + if self.counter.warningCount > 0: + self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." ) + else: + self.logger.info( f"{ result }." ) + + except ChildProcessError as e: + self.logger.error( f"The plugin { self.logger.name } failed due to:\n{ e }" ) + except Exception as e: + mess = f"The plugin { self.logger.name } failed due to:\n{ e }" + self.logger.critical( mess, exc_info=True ) outputMesh.Modified() self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py index 0b446062..473cd475 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py @@ -148,9 +148,11 @@ def __init__( self: Self ) -> None: counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -355,7 +357,7 @@ def RequestData( else: self.logger.info( f"{ result }." ) - except ( ValueError, VTKError, AttributeError, AssertionError ) as e: + except ChildProcessError as e: self.logger.error( f"The plugin { self.logger.name } failed due to:\n{ e }" ) except Exception as e: mess: str = f"The plugin { self.logger.name } failed due to:\n{ e }" @@ -364,6 +366,9 @@ def RequestData( self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return 1 def applyPVGeosBlockExtractAndMerge( self: Self ) -> None: @@ -402,6 +407,10 @@ def applyPVGeomechanicsCalculator( self: Self ) -> None: geomechanicsCalculatorPlugin.Update() # Add to the warning counter the number of warning logged with the call of GeomechanicsCalculator plugin self.counter.addExternalWarningCount( geomechanicsCalculatorPlugin.nbWarnings ) + # Add to the error counter the number of error logged with the call of GeomechanicsCalculator plugin + self.counter.addExternalErrorCount( geomechanicsCalculatorPlugin.nbErrors ) + if self.counter.errorCount != 0: + raise ChildProcessError( "Error during the processing of the plugin PVGeomechanicsCalculators." ) self.volumeMesh.ShallowCopy( geomechanicsCalculatorPlugin.GetOutputDataObject( 0 ) ) self.volumeMesh.Modified() diff --git a/geos-utils/src/geos/utils/Logger.py b/geos-utils/src/geos/utils/Logger.py index fdb4dcff..bde64b7d 100644 --- a/geos-utils/src/geos/utils/Logger.py +++ b/geos-utils/src/geos/utils/Logger.py @@ -103,7 +103,8 @@ class CountWarningHandler( logging.Handler ): def __init__( self: Self ) -> None: """Init the handler.""" super().__init__() - self.warningCount = 0 + self.warningCount: int = 0 + self.errorCount: int = 0 def resetWarningCount( self: Self, value: int = 0 ) -> None: """Set the warning counter to a specific value. @@ -114,6 +115,15 @@ def resetWarningCount( self: Self, value: int = 0 ) -> None: """ self.warningCount = value + def resetErrorCount( self: Self, value: int = 0 ) -> None: + """Set the error counter to a specific value. + + Args: + value (optional, int): The value to set for the error counter. + Defaults to 0. + """ + self.errorCount = value + def addExternalWarningCount( self: Self, externalWarningCount: int ) -> None: """Add external warning count. @@ -122,6 +132,14 @@ def addExternalWarningCount( self: Self, externalWarningCount: int ) -> None: """ self.warningCount += externalWarningCount + def addExternalErrorCount( self: Self, externalErrorCount: int ) -> None: + """Add external error count. + + Args: + externalErrorCount (int): An external error count to add to the internal one. + """ + self.errorCount += externalErrorCount + def emit( self: Self, record: logging.LogRecord ) -> None: """Count all the warnings logged. @@ -131,6 +149,9 @@ def emit( self: Self, record: logging.LogRecord ) -> None: if record.levelno == logging.WARNING: self.warningCount += 1 + if record.levelno >= logging.ERROR: + self.errorCount += 1 + def getLoggerHandlerType( handlerType: type, logger: logging.Logger ) -> logging.Handler: """Get the logger handler with a certain type. From ee9d21963ba5278c8e0fce276fd2efb7ed580124 Mon Sep 17 00:00:00 2001 From: Romain Baville Date: Fri, 20 Feb 2026 13:58:48 +0100 Subject: [PATCH 2/6] Refactor SurfaceGeomechanics to stop workflow if an error is logged --- .../post_processing/SurfaceGeomechanics.py | 22 +++-- .../tests/test_SurfaceGeomechanics.py | 11 ++- .../PVGeomechanicsCalculator.py | 4 +- .../post_processing/PVGeomechanicsWorkflow.py | 4 + .../post_processing/PVSurfaceGeomechanics.py | 89 +++++++++++-------- 5 files changed, 80 insertions(+), 50 deletions(-) diff --git a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py index 7fbf71a5..d290a5ab 100644 --- a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py +++ b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py @@ -122,18 +122,17 @@ def __init__( counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) self.logger.addHandler( self.counter ) - # Input surfacic mesh - if not surfacicMesh.IsA( "vtkPolyData" ): - self.logger.error( f"Input surface is expected to be a vtkPolyData, not a { type( surfacicMesh ) }." ) self.inputMesh: vtkPolyData = surfacicMesh # Identification of the input surface (logging purpose) self.name: Union[ str, None ] = None @@ -241,6 +240,7 @@ def applyFilter( self: Self ) -> None: """Compute Geomechanical properties on input surface. Raises: + TypeError: Error With the type of the input mesh. ValueError: Errors during the creation of an attribute. VTKError: Error raises during the call of VTK function. AttributeError: Attributes must be on cell. @@ -248,6 +248,10 @@ def applyFilter( self: Self ) -> None: """ self.logger.info( f"Apply filter { self.logger.name }." ) + # Input surfacic mesh + if not self.inputMesh.IsA( "vtkPolyData" ): + raise TypeError( f"Input surface is expected to be a vtkPolyData, not a { type( self.inputMesh ) }." ) + self.outputMesh = vtkPolyData() self.outputMesh.ShallowCopy( self.inputMesh ) @@ -268,6 +272,9 @@ def applyFilter( self: Self ) -> None: self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return def convertAttributesFromLocalToXYZBasis( self: Self ) -> None: @@ -352,6 +359,9 @@ def __computeXYZCoordinates( Returns: npt.NDArray[np.float64]: Vector of new coordinates of the attribute. + + Raises: + ValueError: Error with the shape of attrArray or the computation of the attribute coordinate. """ attrXYZ: npt.NDArray[ np.float64 ] = np.full_like( attrArray, np.nan ) @@ -369,16 +379,12 @@ def __computeXYZCoordinates( attrXYZ[ i ] = convertAttributeFromLocalToXYZForOneCell( cellAttribute, cellLocalBasis ) if not np.any( np.isfinite( attrXYZ ) ): - self.logger.error( "Attribute new coordinate calculation failed." ) + raise ValueError( "Attribute new coordinate calculation failed." ) return attrXYZ def computeShearCapacityUtilization( self: Self ) -> None: """Compute the shear capacity utilization (SCU) on surface. - - Raises: - ValueError: Something went wrong during the creation of an attribute. - AssertionError: Something went wrong during the shearCapacityUtilization computation. """ SCUAttributeName: str = PostProcessingOutputsEnum.SCU.attributeName diff --git a/geos-processing/tests/test_SurfaceGeomechanics.py b/geos-processing/tests/test_SurfaceGeomechanics.py index a073ad48..e59191e1 100644 --- a/geos-processing/tests/test_SurfaceGeomechanics.py +++ b/geos-processing/tests/test_SurfaceGeomechanics.py @@ -6,7 +6,7 @@ import pytest from typing import Any -from vtkmodules.vtkCommonDataModel import vtkPolyData +from vtkmodules.vtkCommonDataModel import vtkPolyData, vtkUnstructuredGrid from geos.processing.post_processing.SurfaceGeomechanics import SurfaceGeomechanics @@ -23,7 +23,14 @@ def test_SurfaceGeomechanics( dataSetTest: Any ) -> None: assert mesh.GetCellData().HasArray( "displacementJump_XYZ" ) -def test_failingSurfaceGeomechanics() -> None: +def test_SurfaceGeomechanicsTypeError() -> None: + """Test failing of SurfaceGeomechanics with a vtkUnstructuredGrid as input mesh.""" + sgFilter: SurfaceGeomechanics = SurfaceGeomechanics( vtkUnstructuredGrid() ) + with pytest.raises( TypeError ): + sgFilter.applyFilter() + + +def test_SurfaceGeomechanicsAttributeError() -> None: """Test failing of SurfaceGeomechanics due to absence of attributes in the mesh.""" sgFilter: SurfaceGeomechanics = SurfaceGeomechanics( vtkPolyData() ) with pytest.raises( AttributeError ): diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py index bbeb98bc..d3c37b49 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py @@ -324,10 +324,10 @@ def ApplyFilter( volumeBlock.ShallowCopy( geomechanicsCalculatorFilter.getOutput() ) volumeBlock.Modified() except ( ValueError, AttributeError ) as e: - geomechanicsCalculatorFilter.logger.error( f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" ) + geomechanicsCalculatorFilter.logger.error( f"The filter { filterName } failed due to:\n{ e }" ) raise ChildProcessError( f"Error during the processing of: { filterName }." ) except Exception as e: - mess = f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" + mess = f"The filter { filterName } failed due to:\n{ e }" geomechanicsCalculatorFilter.logger.critical( mess, exc_info=True ) raise ChildProcessError( f"Critical error during the processing of: { filterName }." ) diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py index 473cd475..cad3124e 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py @@ -427,6 +427,10 @@ def applyPVSurfaceGeomechanics( self: Self ) -> None: surfaceGeomechanicsPlugin.Update() # Add to the warning counter the number of warning logged with the call of SurfaceGeomechanics plugin self.counter.addExternalWarningCount( surfaceGeomechanicsPlugin.nbWarnings ) + # Add to the error counter the number of error logged with the call of SurfaceGeomechanics plugin + self.counter.addExternalErrorCount( surfaceGeomechanicsPlugin.nbErrors ) + if self.counter.errorCount != 0: + raise ChildProcessError( "Error during the processing of the plugin PVSurfaceGeomechanics." ) self.faultMesh.ShallowCopy( surfaceGeomechanicsPlugin.GetOutputDataObject( 0 ) ) self.faultMesh.Modified() diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py index 2cbc5ba2..158fb538 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py @@ -79,9 +79,11 @@ def __init__( self: Self ) -> None: counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -140,49 +142,60 @@ def ApplyFilter( self: Self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMul self.logger.info( f"Apply plugin { self.logger.name }." ) outputMesh.ShallowCopy( inputMesh ) - - surfaceBlockIndexes: list[ int ] = getBlockElementIndexesFlatten( inputMesh ) - for blockIndex in surfaceBlockIndexes: - surfaceBlock: vtkPolyData = vtkPolyData.SafeDownCast( getBlockFromFlatIndex( outputMesh, blockIndex ) ) - - loggerName: str = f"Surface geomechanics for the blockIndex { blockIndex }" - sgFilter: SurfaceGeomechanics = SurfaceGeomechanics( surfaceBlock, loggerName, True ) - - if not isHandlerInLogger( self.handler, sgFilter.logger ): - sgFilter.SetLoggerHandler( self.handler ) - - sgFilter.SetRockCohesion( self._getRockCohesion() ) - sgFilter.SetFrictionAngle( self._getFrictionAngle() ) - - try: - sgFilter.applyFilter() - # Add to the warning counter the number of warning logged with the call of SurfaceGeomechanics filter - self.counter.addExternalWarningCount( sgFilter.nbWarnings ) - - outputSurface: vtkPolyData = sgFilter.GetOutputMesh() - - # add attributes to output surface mesh - for attributeName in sgFilter.GetNewAttributeNames(): - attr: vtkDataArray = outputSurface.GetCellData().GetArray( attributeName ) - surfaceBlock.GetCellData().AddArray( attr ) - surfaceBlock.GetCellData().Modified() - surfaceBlock.Modified() - except ( ValueError, VTKError, AttributeError, AssertionError ) as e: - sgFilter.logger.error( f"The filter { sgFilter.logger.name } failed due to:\n{ e }" ) - except Exception as e: - mess: str = f"The filter { sgFilter.logger.name } failed due to:\n{ e }" - sgFilter.logger.critical( mess, exc_info=True ) - - result: str = f"The plugin { self.logger.name } succeeded" - if self.counter.warningCount > 0: - self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." ) - else: - self.logger.info( f"{ result }." ) + try: + surfaceBlockIndexes: list[ int ] = getBlockElementIndexesFlatten( inputMesh ) + for blockIndex in surfaceBlockIndexes: + surfaceBlock: vtkPolyData = vtkPolyData.SafeDownCast( getBlockFromFlatIndex( outputMesh, blockIndex ) ) + + loggerName: str = f"Surface geomechanics for the blockIndex { blockIndex }" + sgFilter: SurfaceGeomechanics = SurfaceGeomechanics( surfaceBlock, loggerName, True ) + + if not isHandlerInLogger( self.handler, sgFilter.logger ): + sgFilter.SetLoggerHandler( self.handler ) + + sgFilter.SetRockCohesion( self._getRockCohesion() ) + sgFilter.SetFrictionAngle( self._getFrictionAngle() ) + + try: + sgFilter.applyFilter() + # Add to the warning counter the number of warning logged with the call of SurfaceGeomechanics filter + self.counter.addExternalWarningCount( sgFilter.nbWarnings ) + + outputSurface: vtkPolyData = sgFilter.GetOutputMesh() + + # add attributes to output surface mesh + for attributeName in sgFilter.GetNewAttributeNames(): + attr: vtkDataArray = outputSurface.GetCellData().GetArray( attributeName ) + surfaceBlock.GetCellData().AddArray( attr ) + surfaceBlock.GetCellData().Modified() + surfaceBlock.Modified() + except ( ValueError, VTKError, AttributeError, AssertionError ) as e: + sgFilter.logger.error( f"The filter { loggerName } failed due to:\n{ e }" ) + raise ChildProcessError( f"Error during the processing of: { loggerName }." ) + except Exception as e: + mess: str = f"The filter { loggerName } failed due to:\n{ e }" + sgFilter.logger.critical( mess, exc_info=True ) + raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) + + result: str = f"The plugin { self.logger.name } succeeded" + if self.counter.warningCount > 0: + self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." ) + else: + self.logger.info( f"{ result }." ) + + except ChildProcessError as e: + self.logger.error( f"The plugin { self.logger.name } failed due to:\n{ e }" ) + except Exception as e: + mess = f"The plugin { self.logger.name } failed due to:\n{ e }" + self.logger.critical( mess, exc_info=True ) outputMesh.Modified() self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return def _getFrictionAngle( self: Self ) -> float: From b6b796cbc7afa6f10d137960504d18f02404ede4 Mon Sep 17 00:00:00 2001 From: Romain Baville Date: Fri, 20 Feb 2026 14:52:28 +0100 Subject: [PATCH 3/6] Refactor Extract and Merge blocks to stop workflow if an error is logged --- .../post_processing/GeosBlockExtractor.py | 5 ++++ .../post_processing/GeosBlockMerge.py | 5 ++++ .../post_processing/PVGeomechanicsWorkflow.py | 4 +++ .../PVGeosBlockExtractAndMerge.py | 7 ++++- .../src/geos/pv/utils/workflowFunctions.py | 29 +++++++++++++++++-- 5 files changed, 47 insertions(+), 3 deletions(-) diff --git a/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py b/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py index b0adcf06..af797f60 100644 --- a/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py +++ b/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py @@ -196,9 +196,11 @@ def __init__( counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -248,4 +250,7 @@ def applyFilter( self: Self ) -> None: self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return diff --git a/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py b/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py index 57074422..244c6110 100644 --- a/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py +++ b/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py @@ -114,9 +114,11 @@ def __init__( counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -201,6 +203,9 @@ def applyFilter( self: Self ) -> None: self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return def renameAttributes( diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py index cad3124e..b801e8f8 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py @@ -378,6 +378,10 @@ def applyPVGeosBlockExtractAndMerge( self: Self ) -> None: extractAndMergeFilter.Update() # Add to the warning counter the number of warning logged with the call of GeosBlockExtractAndMerge plugin self.counter.addExternalWarningCount( extractAndMergeFilter.nbWarnings ) + # Add to the error counter the number of error logged with the call of GeosBlockExtractAndMerge plugin + self.counter.addExternalErrorCount( extractAndMergeFilter.nbErrors ) + if self.counter.errorCount != 0: + raise ChildProcessError( "Error during the processing of the plugin PVGeosBlockExtractAndMerge." ) self.volumeMesh.ShallowCopy( extractAndMergeFilter.GetOutputDataObject( 0 ) ) self.volumeMesh.Modified() diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py index dff27de7..5cdfb2b2 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py @@ -138,9 +138,11 @@ def __init__( self: Self ) -> None: counter: CountWarningHandler = CountWarningHandler() self.counter: CountWarningHandler self.nbWarnings: int = 0 + self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() + self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -333,7 +335,7 @@ def RequestData( self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." ) else: self.logger.info( f"{ result }." ) - except ( ValueError, VTKError ) as e: + except ChildProcessError as e: self.logger.error( f"The plugin { self.logger.name } failed due to:\n{ e }" ) except Exception as e: mess = f"The plugin { self.logger.name } failed due to:\n{ e }" @@ -342,4 +344,7 @@ def RequestData( self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() + self.nbErrors = self.counter.errorCount + self.counter.resetErrorCount() + return 1 diff --git a/geos-pv/src/geos/pv/utils/workflowFunctions.py b/geos-pv/src/geos/pv/utils/workflowFunctions.py index 1a66f1a7..1d51b7ea 100644 --- a/geos-pv/src/geos/pv/utils/workflowFunctions.py +++ b/geos-pv/src/geos/pv/utils/workflowFunctions.py @@ -6,6 +6,7 @@ from geos.processing.post_processing.GeosBlockExtractor import GeosBlockExtractor from geos.processing.post_processing.GeosBlockMerge import GeosBlockMerge from geos.utils.Logger import ( CountWarningHandler, isHandlerInLogger ) +from geos.utils.Errors import VTKError from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet @@ -31,6 +32,9 @@ def doExtractAndMerge( extractFault (bool): True if SurfaceElementRegion needs to be extracted, False otherwise. extractWell (bool): True if WellElementRegion needs to be extracted, False otherwise. warningCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. + + Raises: + ChildProcessError: Error during the call of GeosBlockMerge or GeosBlockExtractor filter. """ # Extract blocks blockExtractor: GeosBlockExtractor = GeosBlockExtractor( mesh, @@ -41,7 +45,16 @@ def doExtractAndMerge( if not isHandlerInLogger( handler, blockExtractor.logger ): blockExtractor.setLoggerHandler( handler ) - blockExtractor.applyFilter() + try: + blockExtractor.applyFilter() + except ( ValueError, TypeError ) as e: + blockExtractor.logger.error( f"The filter { blockExtractor.logger.name } failed due to: { e }." ) + raise ChildProcessError( f"Error during the processing of: { blockExtractor.logger.name }." ) + except Exception as e: + mess: str = f"The filter { blockExtractor.logger.name } failed du to: { e }" + blockExtractor.logger.critical( mess, exc_info=True ) + raise ChildProcessError( f"Critical error during the processing of: { blockExtractor.logger.name }." ) + # Add to the warning counter the number of warning logged with the call of GeosBlockExtractor filter warningCounter.addExternalWarningCount( blockExtractor.nbWarnings ) @@ -81,6 +94,9 @@ def mergeBlocksFilter( Returns: vtkMultiBlockDataSet: Mesh composed of internal merged blocks. + + Raises: + ChildProcessError: Error during the call of GeosBlockMerge filter. """ loggerName = f"GEOS Block Merge for the domain { domainToMerge }" mergeBlockFilter: GeosBlockMerge = GeosBlockMerge( mesh, convertSurfaces, True, loggerName ) @@ -88,7 +104,16 @@ def mergeBlocksFilter( if not isHandlerInLogger( handler, mergeBlockFilter.logger ): mergeBlockFilter.setLoggerHandler( handler ) - mergeBlockFilter.applyFilter() + try: + mergeBlockFilter.applyFilter() + except ( ValueError, VTKError ) as e: + mergeBlockFilter.logger.error( f"The filter { mergeBlockFilter.logger.name } failed due to: { e }" ) + raise ChildProcessError( f"Error during the processing of: { loggerName }." ) + except Exception as e: + mess: str = f"The filter { mergeBlockFilter.logger.name } failed due to: { e }" + mergeBlockFilter.logger.critical( mess, exc_info=True ) + raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) + # Add to the warning counter the number of warning logged with the call of GeosBlockMerge filter warningCounter.addExternalWarningCount( mergeBlockFilter.nbWarnings ) From 7207a02c044e764e730e37f9835f0509a22907ad Mon Sep 17 00:00:00 2001 From: Romain Baville Date: Fri, 20 Feb 2026 16:00:29 +0100 Subject: [PATCH 4/6] Rename CountWarningHandler to CountVerbosityHandler --- .../AttributeMapping.py | 6 +-- .../ClipToMainFrame.py | 6 +-- .../CreateConstantAttributePerRegion.py | 6 +-- .../FillPartialArrays.py | 6 +-- .../MergeBlockEnhanced.py | 6 +-- .../generic_processing_tools/SplitMesh.py | 6 +-- .../post_processing/GeomechanicsCalculator.py | 6 +-- .../post_processing/GeosBlockExtractor.py | 6 +-- .../post_processing/GeosBlockMerge.py | 6 +-- .../post_processing/SurfaceGeomechanics.py | 6 +-- .../pre_processing/CellTypeCounterEnhanced.py | 6 +-- .../pre_processing/MeshQualityEnhanced.py | 6 +-- .../PVGeomechanicsCalculator.py | 6 +-- .../post_processing/PVGeomechanicsWorkflow.py | 6 +-- .../PVGeosBlockExtractAndMerge.py | 6 +-- .../post_processing/PVGeosLogReader.py | 6 +-- .../post_processing/PVMohrCirclePlot.py | 6 +-- .../post_processing/PVSurfaceGeomechanics.py | 6 +-- .../src/geos/pv/utils/workflowFunctions.py | 24 +++++------ geos-utils/src/geos/utils/Logger.py | 6 +-- geos-utils/tests/test_Logger.py | 42 ++++++++++++++++--- 21 files changed, 105 insertions(+), 75 deletions(-) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py b/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py index d1bf2185..ad56823b 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py @@ -9,7 +9,7 @@ from vtkmodules.vtkCommonDataModel import vtkDataSet, vtkMultiBlockDataSet from geos.mesh.utils.arrayModifiers import transferAttributeWithElementMap from geos.mesh.utils.arrayHelpers import ( computeElementMapping, getAttributeSet, isAttributeGlobal ) -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.pieceEnum import Piece __doc__ = """ @@ -111,8 +111,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py b/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py index 4654e6ee..249fce9b 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py @@ -16,7 +16,7 @@ from vtkmodules.vtkCommonTransforms import vtkLandmarkTransform from vtkmodules.vtkFiltersGeneral import vtkTransformFilter -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.mesh.utils.genericHelpers import getMultiBlockBounds __doc__ = """ @@ -237,8 +237,8 @@ def __init__( self, speHandler: bool = False, **properties: str ) -> None: self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py b/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py index da781558..e0097fd3 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py @@ -12,7 +12,7 @@ from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet, vtkDataSet from geos.utils.pieceEnum import Piece -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.mesh.utils.arrayHelpers import ( getArrayInObject, getComponentNames, getAttributePieceInfo, getVtkArrayTypeInObject, getNumberOfComponents, checkValidValuesInObject ) from geos.mesh.utils.arrayModifiers import ( createAttribute, createConstantAttribute ) @@ -129,8 +129,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py b/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py index 2c901473..12c46995 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py @@ -6,7 +6,7 @@ from typing import Union, Any from geos.utils.pieceEnum import Piece -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.mesh.utils.arrayModifiers import fillPartialAttributes from geos.mesh.utils.arrayHelpers import getAttributePieceInfo @@ -98,8 +98,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py b/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py index 88f366fc..fd8b8ce3 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py @@ -6,7 +6,7 @@ from typing_extensions import Self -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.mesh.utils.multiblockModifiers import mergeBlocks from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet, vtkUnstructuredGrid @@ -91,8 +91,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py b/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py index 2695c8f8..511e8a14 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py @@ -12,7 +12,7 @@ VTK_POLYHEDRON, VTK_POLYGON ) from vtkmodules.util.numpy_support import numpy_to_vtk, vtk_to_numpy -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.processing.pre_processing.CellTypeCounterEnhanced import CellTypeCounterEnhanced from geos.mesh.model.CellTypeCounts import CellTypeCounts @@ -84,8 +84,8 @@ def __init__( self, inputMesh: vtkUnstructuredGrid, speHandler: bool = False ) - self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py b/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py index 545498fc..be4be8ea 100644 --- a/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py +++ b/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py @@ -16,7 +16,7 @@ from geos.mesh.utils.arrayHelpers import ( getArrayInObject, isAttributeInObject ) from geos.utils.pieceEnum import Piece -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.GeosOutputsConstants import ( AttributeEnum, ComponentNameEnum, GeosMeshOutputsEnum, PostProcessingOutputsEnum ) from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_RAD, DEFAULT_GRAIN_BULK_MODULUS, @@ -712,8 +712,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py b/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py index af797f60..c8ccd1db 100644 --- a/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py +++ b/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from typing_extensions import Self -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.GeosOutputsConstants import GeosDomainNameEnum from geos.mesh.utils.arrayHelpers import getCellDimension from geos.mesh.utils.multiblockHelpers import getBlockIndexFromName @@ -193,8 +193,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py b/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py index 244c6110..a3cae9df 100644 --- a/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py +++ b/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py @@ -8,7 +8,7 @@ from vtkmodules.vtkCommonDataModel import vtkCompositeDataSet, vtkMultiBlockDataSet, vtkPolyData, vtkUnstructuredGrid from geos.utils.pieceEnum import Piece -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.GeosOutputsConstants import ( PHASE_SEP, PhaseTypeEnum, FluidPrefixEnum, PostProcessingOutputsEnum, getRockSuffixRenaming ) @@ -111,8 +111,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py index d290a5ab..49f4dea5 100644 --- a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py +++ b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py @@ -16,7 +16,7 @@ from geos.mesh.utils.genericHelpers import ( getLocalBasisVectors, convertAttributeFromLocalToXYZForOneCell ) import geos.geomechanics.processing.geomechanicsCalculatorFunctions as fcts from geos.utils.pieceEnum import Piece -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_RAD, DEFAULT_ROCK_COHESION ) from geos.utils.GeosOutputsConstants import ( ComponentNameEnum, GeosMeshOutputsEnum, PostProcessingOutputsEnum ) @@ -119,8 +119,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py b/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py index 6f739109..9dbd82da 100644 --- a/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py +++ b/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py @@ -9,7 +9,7 @@ from geos.mesh.model.CellTypeCounts import CellTypeCounts from geos.mesh.stats.meshQualityMetricHelpers import getAllCellTypes -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) __doc__ = """ CellTypeCounterEnhanced module is a vtk filter that computes cell type counts. @@ -77,8 +77,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py b/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py index 0e75daff..03d8d447 100644 --- a/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py +++ b/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py @@ -28,7 +28,7 @@ getChildrenCellTypes ) import geos.utils.geometryFunctions as geom -from geos.utils.Logger import ( getLogger, Logger, CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( getLogger, Logger, CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.pieceEnum import Piece __doc__ = """ @@ -142,8 +142,8 @@ def __init__( self.logger.setLevel( logging.INFO ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py index d3c37b49..3b3f88fe 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py @@ -23,7 +23,7 @@ update_paths() -from geos.utils.Logger import ( CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_DEG, DEFAULT_GRAIN_BULK_MODULUS, DEFAULT_ROCK_COHESION, WATER_DENSITY ) from geos.mesh.utils.multiblockHelpers import ( getBlockElementIndexesFlatten, getBlockNameFromIndex ) @@ -99,8 +99,8 @@ def __init__( self: Self ) -> None: self.logger.addHandler( self.handler ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py index b801e8f8..390d8d3b 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py @@ -16,7 +16,7 @@ update_paths() from geos.utils.Errors import VTKError -from geos.utils.Logger import ( CountWarningHandler, getLoggerHandlerType ) +from geos.utils.Logger import ( CountVerbosityHandler, getLoggerHandlerType ) from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_DEG, DEFAULT_GRAIN_BULK_MODULUS, DEFAULT_ROCK_COHESION, WATER_DENSITY ) @@ -145,8 +145,8 @@ def __init__( self: Self ) -> None: self.logger.addHandler( self.handler ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py index 5cdfb2b2..6b8ea96a 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py @@ -23,7 +23,7 @@ from geos.utils.Errors import VTKError from geos.utils.pieceEnum import Piece -from geos.utils.Logger import ( CountWarningHandler, getLoggerHandlerType ) +from geos.utils.Logger import ( CountVerbosityHandler, getLoggerHandlerType ) from geos.utils.GeosOutputsConstants import ( GeosMeshOutputsEnum, GeosDomainNameEnum, getAttributeToTransferFromInitialTime ) @@ -135,8 +135,8 @@ def __init__( self: Self ) -> None: self.logger.addHandler( self.handler ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosLogReader.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosLogReader.py index 4b8aea9f..0626496c 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosLogReader.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosLogReader.py @@ -39,7 +39,7 @@ from geos.pv.geosLogReaderUtils.GeosLogReaderWells import GeosLogReaderWells from geos.utils.enumUnits import ( Mass, MassRate, Pressure, Time, Unit, Volume, VolumetricRate, enumerationDomainUnit ) from geos.utils.UnitRepository import UnitRepository -from geos.utils.Logger import ( CountWarningHandler, getLoggerHandlerType ) +from geos.utils.Logger import ( CountVerbosityHandler, getLoggerHandlerType ) from geos.pv.utils.checkboxFunction import createModifiedCallback # type: ignore[attr-defined] from geos.pv.utils.paraviewTreatments import strListToEnumerationDomainXml @@ -156,8 +156,8 @@ def __init__( self: Self ) -> None: self.logger.addHandler( self.handler ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVMohrCirclePlot.py b/geos-pv/src/geos/pv/plugins/post_processing/PVMohrCirclePlot.py index e3ff2585..ae9e7561 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVMohrCirclePlot.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVMohrCirclePlot.py @@ -32,7 +32,7 @@ from geos.geomechanics.model.MohrCircle import MohrCircle from geos.utils.pieceEnum import Piece -from geos.utils.Logger import CountWarningHandler +from geos.utils.Logger import CountVerbosityHandler from geos.utils.enumUnits import Pressure, enumerationDomainUnit from geos.utils.GeosOutputsConstants import ( FAILURE_ENVELOPE, GeosMeshOutputsEnum ) from geos.utils.Logger import ( getLoggerHandlerType ) @@ -187,8 +187,8 @@ def __init__( self: Self ) -> None: self.logger.addHandler( self.handler ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py index 158fb538..e5fa4b58 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py @@ -22,7 +22,7 @@ update_paths() from geos.utils.Errors import VTKError -from geos.utils.Logger import ( CountWarningHandler, isHandlerInLogger, getLoggerHandlerType ) +from geos.utils.Logger import ( CountVerbosityHandler, isHandlerInLogger, getLoggerHandlerType ) from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_DEG, DEFAULT_ROCK_COHESION ) from geos.processing.post_processing.SurfaceGeomechanics import SurfaceGeomechanics from geos.mesh.utils.multiblockHelpers import ( getBlockElementIndexesFlatten, getBlockFromFlatIndex ) @@ -76,8 +76,8 @@ def __init__( self: Self ) -> None: self.logger.addHandler( self.handler ) self.logger.propagate = False - counter: CountWarningHandler = CountWarningHandler() - self.counter: CountWarningHandler + counter: CountVerbosityHandler = CountVerbosityHandler() + self.counter: CountVerbosityHandler self.nbWarnings: int = 0 self.nbErrors: int = 0 try: diff --git a/geos-pv/src/geos/pv/utils/workflowFunctions.py b/geos-pv/src/geos/pv/utils/workflowFunctions.py index 1d51b7ea..da9df04f 100644 --- a/geos-pv/src/geos/pv/utils/workflowFunctions.py +++ b/geos-pv/src/geos/pv/utils/workflowFunctions.py @@ -5,7 +5,7 @@ import logging from geos.processing.post_processing.GeosBlockExtractor import GeosBlockExtractor from geos.processing.post_processing.GeosBlockMerge import GeosBlockMerge -from geos.utils.Logger import ( CountWarningHandler, isHandlerInLogger ) +from geos.utils.Logger import ( CountVerbosityHandler, isHandlerInLogger ) from geos.utils.Errors import VTKError from vtkmodules.vtkCommonDataModel import vtkMultiBlockDataSet @@ -20,7 +20,7 @@ def doExtractAndMerge( outputWells: vtkMultiBlockDataSet, extractFault: bool, extractWell: bool, - warningCounter: CountWarningHandler, + verbosityCounter: CountVerbosityHandler, ) -> None: """Apply block extraction and merge. @@ -31,7 +31,7 @@ def doExtractAndMerge( outputWells (vtkMultiBlockDataSet): Output well mesh extractFault (bool): True if SurfaceElementRegion needs to be extracted, False otherwise. extractWell (bool): True if WellElementRegion needs to be extracted, False otherwise. - warningCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. + verbosityCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. Raises: ChildProcessError: Error during the call of GeosBlockMerge or GeosBlockExtractor filter. @@ -55,22 +55,22 @@ def doExtractAndMerge( blockExtractor.logger.critical( mess, exc_info=True ) raise ChildProcessError( f"Critical error during the processing of: { blockExtractor.logger.name }." ) - # Add to the warning counter the number of warning logged with the call of GeosBlockExtractor filter - warningCounter.addExternalWarningCount( blockExtractor.nbWarnings ) + # Add to the warning count the number of warning logged with the call of GeosBlockExtractor filter + verbosityCounter.addExternalWarningCount( blockExtractor.nbWarnings ) # recover output objects from GeosBlockExtractor filter and merge internal blocks volumeBlockExtracted: vtkMultiBlockDataSet = blockExtractor.extractedGeosDomain.volume - outputCells.ShallowCopy( mergeBlocksFilter( volumeBlockExtracted, warningCounter, False, "Volume" ) ) + outputCells.ShallowCopy( mergeBlocksFilter( volumeBlockExtracted, verbosityCounter, False, "Volume" ) ) outputCells.Modified() if extractFault: faultBlockExtracted: vtkMultiBlockDataSet = blockExtractor.extractedGeosDomain.fault - outputFaults.ShallowCopy( mergeBlocksFilter( faultBlockExtracted, warningCounter, True, "Fault" ) ) + outputFaults.ShallowCopy( mergeBlocksFilter( faultBlockExtracted, verbosityCounter, True, "Fault" ) ) outputFaults.Modified() if extractWell: wellBlockExtracted: vtkMultiBlockDataSet = blockExtractor.extractedGeosDomain.well - outputWells.ShallowCopy( mergeBlocksFilter( wellBlockExtracted, warningCounter, False, "Well" ) ) + outputWells.ShallowCopy( mergeBlocksFilter( wellBlockExtracted, verbosityCounter, False, "Well" ) ) outputWells.Modified() return @@ -78,7 +78,7 @@ def doExtractAndMerge( def mergeBlocksFilter( mesh: vtkMultiBlockDataSet, - warningCounter: CountWarningHandler, + verbosityCounter: CountVerbosityHandler, convertSurfaces: bool = False, domainToMerge: str = "Volume", ) -> vtkMultiBlockDataSet: @@ -86,7 +86,7 @@ def mergeBlocksFilter( Args: mesh (vtkMultiBlockDataSet): Mesh to merge. - warningCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. + verbosityCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. convertSurfaces (bool, optional): True to convert surface from vtkUnstructuredGrid to vtkPolyData. Defaults to False. domainToMerge (str, optional): The name of the GEOS domain processed. @@ -114,8 +114,8 @@ def mergeBlocksFilter( mergeBlockFilter.logger.critical( mess, exc_info=True ) raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) - # Add to the warning counter the number of warning logged with the call of GeosBlockMerge filter - warningCounter.addExternalWarningCount( mergeBlockFilter.nbWarnings ) + # Add to the warning count the number of warning logged with the call of GeosBlockMerge filter + verbosityCounter.addExternalWarningCount( mergeBlockFilter.nbWarnings ) mergedBlocks: vtkMultiBlockDataSet = vtkMultiBlockDataSet() mergedBlocks.ShallowCopy( mergeBlockFilter.getOutput() ) diff --git a/geos-utils/src/geos/utils/Logger.py b/geos-utils/src/geos/utils/Logger.py index bde64b7d..b3846e94 100644 --- a/geos-utils/src/geos/utils/Logger.py +++ b/geos-utils/src/geos/utils/Logger.py @@ -97,8 +97,8 @@ def VTKCaptureLog() -> Generator[ Any, Any, Any ]: os.close( savedStderrFd ) -class CountWarningHandler( logging.Handler ): - """Create an handler to count the warnings logged.""" +class CountVerbosityHandler( logging.Handler ): + """Create an handler to count verbosity logged.""" def __init__( self: Self ) -> None: """Init the handler.""" @@ -141,7 +141,7 @@ def addExternalErrorCount( self: Self, externalErrorCount: int ) -> None: self.errorCount += externalErrorCount def emit( self: Self, record: logging.LogRecord ) -> None: - """Count all the warnings logged. + """Count all verbosity (warning, error and higher) logged. Args: record (logging.LogRecord): Record. diff --git a/geos-utils/tests/test_Logger.py b/geos-utils/tests/test_Logger.py index ba9adf18..c0929a32 100644 --- a/geos-utils/tests/test_Logger.py +++ b/geos-utils/tests/test_Logger.py @@ -10,12 +10,12 @@ def test_CountWarningHandler() -> None: - """Test the counter handler class and its methods.""" + """Test the verbosity counter handler class and its methods for the verbosity warning.""" loggerTest: logging.Logger = logging.getLogger( "Test CountWarningHandler" ) loggerTest.setLevel( logging.INFO ) loggerTest.propagate = False - countWarningHandler: internLogger.CountWarningHandler = internLogger.CountWarningHandler() + countWarningHandler: internLogger.CountVerbosityHandler = internLogger.CountVerbosityHandler() countWarningHandler.setLevel( logging.INFO ) loggerTest.addHandler( countWarningHandler ) @@ -36,6 +36,36 @@ def test_CountWarningHandler() -> None: loggerTest.warning( "Add a warning after the handler reset." ) assert countWarningHandler.warningCount == resetValue + 1 +def test_CountErrorHandler() -> None: + """Test the verbosity counter handler class and its methods for the verbosity error and higher.""" + loggerTest: logging.Logger = logging.getLogger( "Test CountErrorHandler" ) + loggerTest.setLevel( logging.INFO ) + loggerTest.propagate = False + + countErrorHandler: internLogger.CountVerbosityHandler = internLogger.CountVerbosityHandler() + countErrorHandler.setLevel( logging.INFO ) + + loggerTest.addHandler( countErrorHandler ) + + nbErrors: int = random.randint( 0, 10 ) + for error in range( nbErrors ): + loggerTest.error( f"Error number { error }." ) + assert countErrorHandler.errorCount == nbErrors + + additionalErrors: int = random.randint( 1, 10 ) + countErrorHandler.addExternalErrorCount( additionalErrors ) + assert countErrorHandler.errorCount == nbErrors + additionalErrors + + resetValue: int = random.randint( 0, 10 ) + countErrorHandler.resetErrorCount( resetValue ) + assert countErrorHandler.errorCount == resetValue + + loggerTest.error( "Add an error after the handler reset." ) + assert countErrorHandler.errorCount == resetValue + 1 + + loggerTest.critical( "Add a critical error, higher than error but style an error." ) + assert countErrorHandler.errorCount == resetValue + 2 + def test_getLoggerHandlerType() -> None: """Test the function to get a logger's handler with a certain type.""" @@ -48,7 +78,7 @@ def test_getLoggerHandlerType() -> None: handlerType1: type = type( handler1 ) loggerTest.addHandler( handler1 ) - handler2: internLogger.CountWarningHandler = internLogger.CountWarningHandler() + handler2: internLogger.CountVerbosityHandler = internLogger.CountVerbosityHandler() handler2.setLevel( logging.INFO ) handlerType2: type = type( handler2 ) loggerTest.addHandler( handler2 ) @@ -84,7 +114,7 @@ def test_getLoggerHandlerTypeValueError() -> None: loggerTest.addHandler( handler1 ) - handler2: internLogger.CountWarningHandler = internLogger.CountWarningHandler() + handler2: internLogger.CountVerbosityHandler = internLogger.CountVerbosityHandler() handler2.setLevel( logging.INFO ) handlerType2: type = type( handler2 ) @@ -104,7 +134,7 @@ def test_hasLoggerHandlerType() -> None: handlerType1: type = type( handler1 ) loggerTest.addHandler( handler1 ) - handler2: internLogger.CountWarningHandler = internLogger.CountWarningHandler() + handler2: internLogger.CountVerbosityHandler = internLogger.CountVerbosityHandler() handler2.setLevel( logging.INFO ) handlerType2: type = type( handler2 ) @@ -122,7 +152,7 @@ def test_isHandlerInLogger() -> None: handler1.setLevel( logging.INFO ) loggerTest.addHandler( handler1 ) - handler2: internLogger.CountWarningHandler = internLogger.CountWarningHandler() + handler2: internLogger.CountVerbosityHandler = internLogger.CountVerbosityHandler() handler2.setLevel( logging.INFO ) handler3: logging.Handler = logging.Handler() From d5f0de06530d8190670f11d091543ddb896882ef Mon Sep 17 00:00:00 2001 From: Romain Baville Date: Fri, 20 Feb 2026 17:20:32 +0100 Subject: [PATCH 5/6] Clean CountVerbosityHandler call and doc --- .../AttributeMapping.py | 1 + .../ClipToMainFrame.py | 1 + .../CreateConstantAttributePerRegion.py | 1 + .../FillPartialArrays.py | 1 + .../MergeBlockEnhanced.py | 1 + .../generic_processing_tools/SplitMesh.py | 1 + .../post_processing/GeomechanicsCalculator.py | 6 +--- .../post_processing/GeosBlockExtractor.py | 6 +--- .../post_processing/GeosBlockMerge.py | 6 +--- .../post_processing/SurfaceGeomechanics.py | 8 ++--- .../pre_processing/CellTypeCounterEnhanced.py | 1 + .../pre_processing/MeshQualityEnhanced.py | 1 + .../PVGeomechanicsCalculator.py | 15 +++++--- .../post_processing/PVGeomechanicsWorkflow.py | 7 ++-- .../PVGeosBlockExtractAndMerge.py | 34 +++++++++++++------ .../post_processing/PVSurfaceGeomechanics.py | 9 ++--- .../src/geos/pv/utils/workflowFunctions.py | 4 +-- 17 files changed, 57 insertions(+), 46 deletions(-) diff --git a/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py b/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py index ad56823b..fd563a8f 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/AttributeMapping.py @@ -209,6 +209,7 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py b/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py index 249fce9b..2bb34fde 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/ClipToMainFrame.py @@ -259,6 +259,7 @@ def Update( self ) -> None: # type: ignore[override] else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py b/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py index e0097fd3..d9aa75a3 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/CreateConstantAttributePerRegion.py @@ -407,6 +407,7 @@ def _logOutputMessage( self: Self, trueIndexes: list[ Any ] ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py b/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py index 12c46995..284c0a81 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/FillPartialArrays.py @@ -162,6 +162,7 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py b/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py index fd8b8ce3..88e33ab6 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/MergeBlockEnhanced.py @@ -134,6 +134,7 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py b/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py index 511e8a14..886d2c9c 100644 --- a/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py +++ b/geos-processing/src/geos/processing/generic_processing_tools/SplitMesh.py @@ -189,6 +189,7 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py b/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py index be4be8ea..70630458 100644 --- a/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py +++ b/geos-processing/src/geos/processing/post_processing/GeomechanicsCalculator.py @@ -715,11 +715,9 @@ def __init__( counter: CountVerbosityHandler = CountVerbosityHandler() self.counter: CountVerbosityHandler self.nbWarnings: int = 0 - self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() - self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -770,12 +768,10 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the CountVerbosityHandler in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() - self.nbErrors = self.counter.errorCount - self.counter.resetErrorCount() - return def getOutput( self: Self ) -> vtkUnstructuredGrid: diff --git a/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py b/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py index c8ccd1db..5f78037a 100644 --- a/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py +++ b/geos-processing/src/geos/processing/post_processing/GeosBlockExtractor.py @@ -196,11 +196,9 @@ def __init__( counter: CountVerbosityHandler = CountVerbosityHandler() self.counter: CountVerbosityHandler self.nbWarnings: int = 0 - self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() - self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -247,10 +245,8 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() - self.nbErrors = self.counter.errorCount - self.counter.resetErrorCount() - return diff --git a/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py b/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py index a3cae9df..3ee1e79d 100644 --- a/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py +++ b/geos-processing/src/geos/processing/post_processing/GeosBlockMerge.py @@ -114,11 +114,9 @@ def __init__( counter: CountVerbosityHandler = CountVerbosityHandler() self.counter: CountVerbosityHandler self.nbWarnings: int = 0 - self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() - self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -200,12 +198,10 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() - self.nbErrors = self.counter.errorCount - self.counter.resetErrorCount() - return def renameAttributes( diff --git a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py index 49f4dea5..50847bfc 100644 --- a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py +++ b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py @@ -65,7 +65,7 @@ # Do calculations try: sg.applyFilter() - except ( ValueError, VTKError, AttributeError, AssertionError ) as e: + except ( ValueError, VTKError, AttributeError, AssertionError, TypeError ) as e: sg.logger.error( f"The filter { sg.logger.name } failed due to: { e }" ) except Exception as e: mess: str = f"The filter { sg.logger.name } failed due to: { e }" @@ -122,11 +122,9 @@ def __init__( counter: CountVerbosityHandler = CountVerbosityHandler() self.counter: CountVerbosityHandler self.nbWarnings: int = 0 - self.nbErrors: int = 0 try: self.counter = getLoggerHandlerType( type( counter ), self.logger ) self.counter.resetWarningCount() - self.counter.resetErrorCount() except ValueError: self.counter = counter self.counter.setLevel( logging.INFO ) @@ -269,12 +267,10 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() - self.nbErrors = self.counter.errorCount - self.counter.resetErrorCount() - return def convertAttributesFromLocalToXYZBasis( self: Self ) -> None: diff --git a/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py b/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py index 9dbd82da..107a77cb 100644 --- a/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py +++ b/geos-processing/src/geos/processing/pre_processing/CellTypeCounterEnhanced.py @@ -139,6 +139,7 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py b/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py index 03d8d447..d299bdc6 100644 --- a/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py +++ b/geos-processing/src/geos/processing/pre_processing/MeshQualityEnhanced.py @@ -324,6 +324,7 @@ def applyFilter( self: Self ) -> None: else: self.logger.info( f"{ result }." ) + # Keep number of warnings logged during the filter application and reset the warnings count in case the filter is apply again. self.nbWarnings = self.counter.warningCount self.counter.resetWarningCount() diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py index 3b3f88fe..af9e34e0 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py @@ -277,18 +277,20 @@ def ApplyFilter( try: geomechanicsCalculatorFilter.applyFilter() - # Add to the warning counter the number of warning logged with the call of GeomechanicsCalculator filter (useful for the PVGeomechanicsWorkflow) + # Add to the warning counter the number of warning logged with the call of GeomechanicsCalculator filter self.counter.addExternalWarningCount( geomechanicsCalculatorFilter.nbWarnings ) outputMesh.ShallowCopy( geomechanicsCalculatorFilter.getOutput() ) except ( ValueError, AttributeError ) as e: geomechanicsCalculatorFilter.logger.error( f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" ) - self.counter.addExternalErrorCount( geomechanicsCalculatorFilter.nbErrors ) + # The logger of the filter is used to log the error, the CountVerbosityHandler of the plugin must be updated + self.counter.addExternalErrorCount( 1 ) except Exception as e: mess = f"The filter { geomechanicsCalculatorFilter.logger.name } failed due to:\n{ e }" geomechanicsCalculatorFilter.logger.critical( mess, exc_info=True ) - self.counter.addExternalErrorCount( geomechanicsCalculatorFilter.nbErrors ) + # The logger of the filter is used to log the error, the CountVerbosityHandler of the plugin must be updated + self.counter.addExternalErrorCount( 1 ) elif isinstance( outputMesh, vtkMultiBlockDataSet ): self.logger.info( f"Apply plugin { self.logger.name }." ) @@ -344,10 +346,13 @@ def ApplyFilter( self.logger.critical( mess, exc_info=True ) outputMesh.Modified() - self.nbWarnings = self.counter.warningCount - self.counter.resetWarningCount() + # Keep number of verbosity logged during the plugin application + self.nbWarnings = self.counter.warningCount self.nbErrors = self.counter.errorCount + + # Reset the CountVerbosityHandler in case the plugin is apply again + self.counter.resetWarningCount() self.counter.resetErrorCount() return diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py index 390d8d3b..2dc17cf2 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsWorkflow.py @@ -15,7 +15,6 @@ update_paths() -from geos.utils.Errors import VTKError from geos.utils.Logger import ( CountVerbosityHandler, getLoggerHandlerType ) from geos.utils.PhysicalConstants import ( DEFAULT_FRICTION_ANGLE_DEG, DEFAULT_GRAIN_BULK_MODULUS, DEFAULT_ROCK_COHESION, WATER_DENSITY ) @@ -363,10 +362,12 @@ def RequestData( mess: str = f"The plugin { self.logger.name } failed due to:\n{ e }" self.logger.critical( mess, exc_info=True ) + # Keep number of verbosity logged during the plugin application self.nbWarnings = self.counter.warningCount - self.counter.resetWarningCount() - self.nbErrors = self.counter.errorCount + + # Reset the CountVerbosityHandler in case the plugin is apply again + self.counter.resetWarningCount() self.counter.resetErrorCount() return 1 diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py index 6b8ea96a..131bd649 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeosBlockExtractAndMerge.py @@ -291,12 +291,17 @@ def RequestData( try: doExtractAndMerge( inputMesh, self.outputCellsT0, vtkMultiBlockDataSet(), vtkMultiBlockDataSet(), self.extractFault, self.extractWell, self.counter ) + # Initialize time step iteration request.Set( executive.CONTINUE_EXECUTING(), 1 ) except ( ValueError, VTKError ) as e: self.logger.error( f"The plugin { self.logger.name } failed due to:\n{ e }" ) + self.resetPlugin() + return 1 except Exception as e: mess = f"The plugin { self.logger.name } failed due to:\n{ e }" self.logger.critical( mess, exc_info=True ) + self.resetPlugin() + return 1 # Current time step, extract, merge, rename and transfer properties if self.requestDataStep == self.currentTimeStepIndex: @@ -324,12 +329,6 @@ def RequestData( if cellCenterAttributeName not in meshAttributes: createCellCenterAttribute( outputCells, cellCenterAttributeName, logger=self.logger ) - # Stop the time step iteration - request.Remove( executive.CONTINUE_EXECUTING() ) - - # Set to -2 in case time changes on Paraview - self.requestDataStep = -2 - result: str = f"The plugin { self.logger.name } succeeded" if self.counter.warningCount > 0: self.logger.warning( f"{ result } but { self.counter.warningCount } warnings have been logged." ) @@ -341,10 +340,23 @@ def RequestData( mess = f"The plugin { self.logger.name } failed due to:\n{ e }" self.logger.critical( mess, exc_info=True ) - self.nbWarnings = self.counter.warningCount - self.counter.resetWarningCount() - - self.nbErrors = self.counter.errorCount - self.counter.resetErrorCount() + # Stop the time step iteration + request.Remove( executive.CONTINUE_EXECUTING() ) + self.resetPlugin() return 1 + + def resetPlugin( self: Self ) -> None: + """Reset the plugin variable to be apply again.""" + # Set to -2 in case time changes on Paraview + self.requestDataStep = -2 + + # Keep number of verbosity logged during the plugin application + self.nbWarnings = self.counter.warningCount + self.nbErrors = self.counter.errorCount + + # Reset the CountVerbosityHandler in case the plugin is apply again + self.counter.resetWarningCount() + self.counter.resetErrorCount() + + return diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py index e5fa4b58..2dec6df8 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py @@ -169,7 +169,7 @@ def ApplyFilter( self: Self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMul surfaceBlock.GetCellData().AddArray( attr ) surfaceBlock.GetCellData().Modified() surfaceBlock.Modified() - except ( ValueError, VTKError, AttributeError, AssertionError ) as e: + except ( ValueError, VTKError, AttributeError, AssertionError, TypeError ) as e: sgFilter.logger.error( f"The filter { loggerName } failed due to:\n{ e }" ) raise ChildProcessError( f"Error during the processing of: { loggerName }." ) except Exception as e: @@ -189,11 +189,12 @@ def ApplyFilter( self: Self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMul mess = f"The plugin { self.logger.name } failed due to:\n{ e }" self.logger.critical( mess, exc_info=True ) - outputMesh.Modified() + # Keep number of verbosity logged during the plugin application self.nbWarnings = self.counter.warningCount - self.counter.resetWarningCount() - self.nbErrors = self.counter.errorCount + + # Reset the CountVerbosityHandler in case the plugin is apply again + self.counter.resetWarningCount() self.counter.resetErrorCount() return diff --git a/geos-pv/src/geos/pv/utils/workflowFunctions.py b/geos-pv/src/geos/pv/utils/workflowFunctions.py index da9df04f..59f7da8a 100644 --- a/geos-pv/src/geos/pv/utils/workflowFunctions.py +++ b/geos-pv/src/geos/pv/utils/workflowFunctions.py @@ -31,7 +31,7 @@ def doExtractAndMerge( outputWells (vtkMultiBlockDataSet): Output well mesh extractFault (bool): True if SurfaceElementRegion needs to be extracted, False otherwise. extractWell (bool): True if WellElementRegion needs to be extracted, False otherwise. - verbosityCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. + verbosityCounter (logging.Handler): The plugin Handler to update with the number of verbosity logged during the call of the extract and merge filters. Raises: ChildProcessError: Error during the call of GeosBlockMerge or GeosBlockExtractor filter. @@ -86,7 +86,7 @@ def mergeBlocksFilter( Args: mesh (vtkMultiBlockDataSet): Mesh to merge. - verbosityCounter (logging.Handler): The plugin Handler to update with the number of warning log during the call of the extract and merge filters. + verbosityCounter (logging.Handler): The plugin Handler to update with the number of verbosity logged during the call of the merge filters. convertSurfaces (bool, optional): True to convert surface from vtkUnstructuredGrid to vtkPolyData. Defaults to False. domainToMerge (str, optional): The name of the GEOS domain processed. From f0207e2d42cf206d326171c5326cfcd49aad082f Mon Sep 17 00:00:00 2001 From: Romain Baville Date: Fri, 20 Feb 2026 18:09:56 +0100 Subject: [PATCH 6/6] clean for the ci --- .../processing/post_processing/SurfaceGeomechanics.py | 3 +-- .../plugins/post_processing/PVGeomechanicsCalculator.py | 4 ++-- .../pv/plugins/post_processing/PVSurfaceGeomechanics.py | 4 ++-- geos-pv/src/geos/pv/utils/workflowFunctions.py | 8 ++++---- geos-utils/tests/test_Logger.py | 1 + 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py index 50847bfc..cf1d97d7 100644 --- a/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py +++ b/geos-processing/src/geos/processing/post_processing/SurfaceGeomechanics.py @@ -380,8 +380,7 @@ def __computeXYZCoordinates( return attrXYZ def computeShearCapacityUtilization( self: Self ) -> None: - """Compute the shear capacity utilization (SCU) on surface. - """ + """Compute the shear capacity utilization (SCU) on surface.""" SCUAttributeName: str = PostProcessingOutputsEnum.SCU.attributeName if not isAttributeInObject( self.outputMesh, SCUAttributeName, self.attributePiece ): diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py index af9e34e0..6cee2983 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVGeomechanicsCalculator.py @@ -327,11 +327,11 @@ def ApplyFilter( volumeBlock.Modified() except ( ValueError, AttributeError ) as e: geomechanicsCalculatorFilter.logger.error( f"The filter { filterName } failed due to:\n{ e }" ) - raise ChildProcessError( f"Error during the processing of: { filterName }." ) + raise ChildProcessError( f"Error during the processing of: { filterName }." ) from e except Exception as e: mess = f"The filter { filterName } failed due to:\n{ e }" geomechanicsCalculatorFilter.logger.critical( mess, exc_info=True ) - raise ChildProcessError( f"Critical error during the processing of: { filterName }." ) + raise ChildProcessError( f"Critical error during the processing of: { filterName }." ) from e result: str = f"The plugin { self.logger.name } succeeded" if self.counter.warningCount > 0: diff --git a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py index 2dec6df8..93ccc1ee 100644 --- a/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py +++ b/geos-pv/src/geos/pv/plugins/post_processing/PVSurfaceGeomechanics.py @@ -171,11 +171,11 @@ def ApplyFilter( self: Self, inputMesh: vtkMultiBlockDataSet, outputMesh: vtkMul surfaceBlock.Modified() except ( ValueError, VTKError, AttributeError, AssertionError, TypeError ) as e: sgFilter.logger.error( f"The filter { loggerName } failed due to:\n{ e }" ) - raise ChildProcessError( f"Error during the processing of: { loggerName }." ) + raise ChildProcessError( f"Error during the processing of: { loggerName }." ) from e except Exception as e: mess: str = f"The filter { loggerName } failed due to:\n{ e }" sgFilter.logger.critical( mess, exc_info=True ) - raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) + raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) from e result: str = f"The plugin { self.logger.name } succeeded" if self.counter.warningCount > 0: diff --git a/geos-pv/src/geos/pv/utils/workflowFunctions.py b/geos-pv/src/geos/pv/utils/workflowFunctions.py index 59f7da8a..460e2028 100644 --- a/geos-pv/src/geos/pv/utils/workflowFunctions.py +++ b/geos-pv/src/geos/pv/utils/workflowFunctions.py @@ -49,11 +49,11 @@ def doExtractAndMerge( blockExtractor.applyFilter() except ( ValueError, TypeError ) as e: blockExtractor.logger.error( f"The filter { blockExtractor.logger.name } failed due to: { e }." ) - raise ChildProcessError( f"Error during the processing of: { blockExtractor.logger.name }." ) + raise ChildProcessError( f"Error during the processing of: { blockExtractor.logger.name }." ) from e except Exception as e: mess: str = f"The filter { blockExtractor.logger.name } failed du to: { e }" blockExtractor.logger.critical( mess, exc_info=True ) - raise ChildProcessError( f"Critical error during the processing of: { blockExtractor.logger.name }." ) + raise ChildProcessError( f"Critical error during the processing of: { blockExtractor.logger.name }." ) from e # Add to the warning count the number of warning logged with the call of GeosBlockExtractor filter verbosityCounter.addExternalWarningCount( blockExtractor.nbWarnings ) @@ -108,11 +108,11 @@ def mergeBlocksFilter( mergeBlockFilter.applyFilter() except ( ValueError, VTKError ) as e: mergeBlockFilter.logger.error( f"The filter { mergeBlockFilter.logger.name } failed due to: { e }" ) - raise ChildProcessError( f"Error during the processing of: { loggerName }." ) + raise ChildProcessError( f"Error during the processing of: { loggerName }." ) from e except Exception as e: mess: str = f"The filter { mergeBlockFilter.logger.name } failed due to: { e }" mergeBlockFilter.logger.critical( mess, exc_info=True ) - raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) + raise ChildProcessError( f"Critical error during the processing of: { loggerName }." ) from e # Add to the warning count the number of warning logged with the call of GeosBlockMerge filter verbosityCounter.addExternalWarningCount( mergeBlockFilter.nbWarnings ) diff --git a/geos-utils/tests/test_Logger.py b/geos-utils/tests/test_Logger.py index c0929a32..6b3edde7 100644 --- a/geos-utils/tests/test_Logger.py +++ b/geos-utils/tests/test_Logger.py @@ -36,6 +36,7 @@ def test_CountWarningHandler() -> None: loggerTest.warning( "Add a warning after the handler reset." ) assert countWarningHandler.warningCount == resetValue + 1 + def test_CountErrorHandler() -> None: """Test the verbosity counter handler class and its methods for the verbosity error and higher.""" loggerTest: logging.Logger = logging.getLogger( "Test CountErrorHandler" )