Browse Source

ref: new flake8 rule S009 + fix exception reraising (#62620)

blank `raise` preserves the original stacktrace

<!-- Describe your PR here. -->

blocked on https://github.com/getsentry/getsentry/pull/12477
anthony sottile 1 year ago
parent
commit
e5c5e56d17

+ 2 - 2
config/hooks/pre-commit

@@ -38,7 +38,7 @@ if "VIRTUAL_ENV" in os.environ:
 def main():
     try:
         from sentry.lint.engine import get_modified_files, run
-    except ModuleNotFoundError as e:
+    except ModuleNotFoundError:
         if "VIRTUAL_ENV" not in os.environ:
             sys.stderr.write(
                 "ERROR: You're executing outside of the venv. Try this command: direnv allow\n"
@@ -47,7 +47,7 @@ def main():
 
         sys.stdout.write("ERROR: You may be able to fix this by executing: make install-py-dev.\n")
 
-        raise (e)
+        raise
 
     files_modified = [text_type(f) for f in get_modified_files(os.getcwd()) if os.path.exists(f)]
 

+ 0 - 2
src/sentry/api/endpoints/group_details.py

@@ -336,8 +336,6 @@ class GroupDetailsEndpoint(GroupEndpoint, EnvironmentMixin):
                 "group_details:put client.ApiError",
             )
             return Response(e.body, status=e.status_code)
-        except Exception:
-            raise
 
     def delete(self, request: Request, group) -> Response:
         """

+ 0 - 2
src/sentry/api/endpoints/project_artifact_bundle_files.py

@@ -136,8 +136,6 @@ class ProjectArtifactBundleFilesEndpoint(ProjectEndpoint):
                 max_offset=MAX_ARTIFACT_BUNDLE_FILES_OFFSET,
                 on_results=serialize_results,
             )
-        except Exception as exc:
-            raise exc
         finally:
             # We must close the archive before returning the value, otherwise we will get an error.
             archive.close()

+ 2 - 2
src/sentry/api/validators/sentry_apps/schema.py

@@ -270,8 +270,8 @@ def validate_ui_element_schema(instance):
         check_elements_is_array(instance)
         check_each_element_for_error(instance)
         check_only_one_of_each_element(instance)
-    except SchemaValidationError as e:
-        raise e
+    except SchemaValidationError:
+        raise
     except Exception as e:
         logger.warning(
             "Unexpected error validating schema: %s",

+ 2 - 2
src/sentry/backup/imports.py

@@ -356,9 +356,9 @@ def _import(
 
                 try:
                     _clear_model_tables_before_import()
-                except DatabaseError as e:
+                except DatabaseError:
                     printer.echo("Database could not be reset before importing")
-                    raise e
+                    raise
             do_writes(pk_map)
     else:
         do_writes(pk_map)

+ 1 - 1
src/sentry/db/postgres/creation.py

@@ -27,4 +27,4 @@ class SentryDatabaseCreation(DatabaseCreation):
             elif not keepdb:
                 # If the database should be kept, ignore "database already
                 # exists".
-                raise e
+                raise

+ 4 - 4
src/sentry/grouping/enhancer/__init__.py

@@ -523,14 +523,14 @@ def _update_frames_from_cached_values(
 
             if frames_changed:
                 logger.debug("We have merged the cached stacktrace to the incoming one.")
-        except Exception as error:
+        except Exception:
             logger.exception(
                 "We have failed to update the stacktrace from the cache. Not aborting execution.",
                 extra={"platform": platform},
             )
             # We want tests to fail to prevent breaking the caching system without noticing
             if os.environ.get("PYTEST_CURRENT_TEST"):
-                raise error
+                raise
 
     metrics.incr(
         f"{DATADOG_KEY}.merged_cached_values",
@@ -588,14 +588,14 @@ def _generate_stacktrace_fingerprint(
         )
 
         stacktrace_fingerprint = stacktrace_hash.hexdigest()
-    except Exception as error:
+    except Exception:
         # This will create an error in Sentry to help us evaluate why it failed
         logger.exception(
             "Stacktrace hashing failure. Investigate and fix.", extra={"platform": platform}
         )
         # We want tests to fail to prevent breaking the caching system without noticing
         if os.environ.get("PYTEST_CURRENT_TEST"):
-            raise error
+            raise
 
     # This will help us calculate the success ratio for fingerprint calculation
     metrics.incr(

+ 1 - 1
src/sentry/identity/gitlab/provider.py

@@ -53,7 +53,7 @@ def get_user_info(access_token, installation_data):
                 "error_message": f"{e}",
             },
         )
-        raise e
+        raise
     return resp.json()
 
 

+ 2 - 2
src/sentry/incidents/charts.py

@@ -81,7 +81,7 @@ def fetch_metric_alert_sessions_data(
             "Failed to load sessions for chart: %s",
             exc,
         )
-        raise exc
+        raise
 
 
 def fetch_metric_alert_events_timeseries(
@@ -119,7 +119,7 @@ def fetch_metric_alert_events_timeseries(
             exc,
             exc_info=True,
         )
-        raise exc
+        raise
 
 
 def fetch_metric_alert_incidents(

+ 1 - 1
src/sentry/integrations/bitbucket/search.py

@@ -59,7 +59,7 @@ class BitbucketSearchEndpoint(IntegrationEndpoint):
                     return Response(
                         {"detail": "Bitbucket Repository has no issue tracker."}, status=400
                     )
-                raise e
+                raise
             return Response(
                 [
                     {"label": "#{} {}".format(i["id"], i["title"]), "value": i["id"]}

Some files were not shown because too many files changed in this diff