Skip to content

Commit 2aa3c8b

Browse files
committed
fix(agent): prevent cleanup exceptions from masking SQL execution errors
1 parent e6b7698 commit 2aa3c8b

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

agent/tools/exesql.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
#
16+
import contextlib
1617
import json
1718
import os
1819
import re
@@ -230,15 +231,17 @@ def _parse_catalog_schema(db: str):
230231
sql_res.append(convert_decimals(df.to_dict(orient="records")))
231232
formalized_content.append(df.to_markdown(index=False, floatfmt=".6f"))
232233
finally:
233-
ibm_db.close(conn)
234+
with contextlib.suppress(Exception):
235+
ibm_db.close(conn)
234236

235237
self.set_output("json", sql_res)
236238
self.set_output("formalized_content", "\n\n".join(formalized_content))
237239
return self.output("formalized_content")
238240
try:
239241
cursor = db.cursor()
240242
except Exception as e:
241-
db.close()
243+
with contextlib.suppress(Exception):
244+
db.close()
242245
raise Exception("Database Connection Failed! \n" + str(e))
243246

244247
try:
@@ -272,8 +275,10 @@ def _parse_catalog_schema(db: str):
272275
sql_res.append(convert_decimals(single_res.to_dict(orient='records')))
273276
formalized_content.append(single_res.to_markdown(index=False, floatfmt=".6f"))
274277
finally:
275-
cursor.close()
276-
db.close()
278+
with contextlib.suppress(Exception):
279+
cursor.close()
280+
with contextlib.suppress(Exception):
281+
db.close()
277282

278283
self.set_output("json", sql_res)
279284
self.set_output("formalized_content", "\n\n".join(formalized_content))

0 commit comments

Comments
 (0)