Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temporal: Fix bare except statements with specific error handling #4805

Merged
merged 2 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading