Skip to content

Commit fb220e5

Browse files
author
shbhmexe
committed
fix(py): remove silent exception handlers in topology_optimization (CodeQL/CodeFactor)
- Replace three `try/except ...: pass` blocks with existence checks before os.remove. - No behavioral change; resolves “Unreachable except block” and “Empty except” findings. Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
1 parent add720b commit fb220e5

1 file changed

Lines changed: 6 additions & 19 deletions

File tree

SU2_PY/topology_optimization.py

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,9 @@ def obj_val(self, x):
120120
# write inputs
121121
self._write_input(x)
122122

123-
# clear previous output and run direct solver
124-
try:
123+
# clear previous output if present and run direct solver
124+
if os.path.exists(self._objValFile):
125125
os.remove(self._objValFile)
126-
except Exception:
127-
pass
128-
except OSError:
129-
pass # Ignore error if file does not exist
130126

131127
try:
132128
sp.call(self._objValCommand, shell=True)
@@ -149,13 +145,9 @@ def obj_val(self, x):
149145
def obj_der(self, x):
150146
# inputs written in obj_val_driver
151147

152-
# clear previous output and run direct solver
153-
try:
148+
# clear previous output if present and run direct solver
149+
if os.path.exists(self._objDerFile):
154150
os.remove(self._objDerFile)
155-
except Exception:
156-
pass
157-
except OSError:
158-
pass # Ignore error if file does not exist
159151
N = x.shape[0]
160152
y = np.ndarray((N,))
161153

@@ -201,14 +193,9 @@ def con_val(self, x):
201193
def con_der(self, x):
202194
# inputs written in obj_val_driver
203195

204-
# clear previous output and run solver
205-
try:
196+
# clear previous output if present and run solver
197+
if os.path.exists(self._conDerFile):
206198
os.remove(self._conDerFile)
207-
except Exception:
208-
pass
209-
210-
except OSError:
211-
pass # Ignore error if file does not exist
212199
N = x.shape[0]
213200
y = np.ndarray((N,))
214201

0 commit comments

Comments
 (0)