Skip to content

Commit

Permalink
temporal: Fix bare except statements with specific error handling (OS…
Browse files Browse the repository at this point in the history
…Geo#4805)

Co-authored-by: Edouard Choinière <[email protected]>
  • Loading branch information
arohanajit and echoix authored Dec 12, 2024
1 parent 3022d9f commit 3b1d889
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 0 additions & 3 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ per-file-ignores =
# TODO: Is this really needed?
python/grass/pygrass/vector/__init__.py: E402
python/grass/pygrass/vector/__init__.py: E402
python/grass/temporal/abstract_space_time_dataset.py: E722
python/grass/temporal/c_libraries_interface.py: E722
python/grass/temporal/core.py: E722
python/grass/temporal/datetime_math.py: E722
python/grass/temporal/spatial_topology_dataset_connector.py: E722
python/grass/temporal/temporal_algebra.py: E722
Expand Down
5 changes: 4 additions & 1 deletion python/grass/temporal/abstract_space_time_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class that is the base class for all space time datasets.
from abc import ABCMeta, abstractmethod
from datetime import datetime
from pathlib import Path
from grass.exceptions import FatalError

from .abstract_dataset import AbstractDataset, AbstractDatasetComparisonKeyStartTime
from .core import (
Expand Down Expand Up @@ -2463,7 +2464,9 @@ def is_map_registered(self, map_id, dbif=None):
try:
dbif.execute(sql, (map_id,), mapset=self.base.mapset)
row = dbif.fetchone(mapset=self.base.mapset)
except:
except FatalError:
raise
except Exception:
self.msgr.warning(_("Error in register table request"))
raise

Expand Down
8 changes: 4 additions & 4 deletions python/grass/temporal/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
try:
import psycopg2
import psycopg2.extras
except:
except ImportError:
pass

import atexit
Expand Down Expand Up @@ -414,7 +414,7 @@ def get_tgis_metadata(dbif=None):
statement = "SELECT * FROM tgis_metadata;\n"
dbif.execute(statement)
rows = dbif.fetchall()
except:
except Exception:
rows = None

if connection_state_changed:
Expand Down Expand Up @@ -1501,7 +1501,7 @@ def execute(self, statement, args=None):
self.cursor.execute(statement, args)
else:
self.cursor.execute(statement)
except:
except (sqlite3.Error, psycopg2.Error):
if connected:
self.close()
self.msgr.error(_("Unable to execute :\n %(sql)s") % {"sql": statement})
Expand Down Expand Up @@ -1544,7 +1544,7 @@ def execute_transaction(self, statement, mapset=None):
else:
self.cursor.execute(statement)
self.connection.commit()
except:
except (sqlite3.Error, psycopg2.Error):
if connected:
self.close()
self.msgr.error(
Expand Down

0 comments on commit 3b1d889

Please sign in to comment.