Taragolis opened a new issue, #38761: URL: https://github.com/apache/airflow/issues/38761
### Body Follow-up task for https://github.com/apache/airflow/pull/38756 We enable this rule for avoid use to broad `Exception` raises in codebase which hard to catch because it always required to catch `Exception` which might catch also other errors (TBH all of the errors which are not subclassed of `BaseException`). ### Easy way to find all linting problem into the module 1. Remove corresponding line to particular module into the [`pyproject.toml`](https://github.com/apache/airflow/blob/main/pyproject.toml#L381) in [tool.ruff.lint.per-file-ignores] related to ignore `TRY002` in providers. 2. Run ruff via [pre-commit](https://github.com/apache/airflow/blob/main/contributing-docs/08_static_code_checks.rst#pre-commit-hooks) hook ```console ❯ pre-commit run ruff --all-files Run 'ruff' for extremely fast Python linting.............................Failed - hook id: ruff - exit code: 1 airflow/providers/docker/operators/docker_swarm.py:150:19: TRY002 Create your own exception airflow/providers/docker/operators/docker_swarm.py:172:23: TRY002 Create your own exception airflow/providers/docker/operators/docker_swarm.py:177:19: TRY002 Create your own exception airflow/providers/docker/operators/docker_swarm.py:186:19: TRY002 Create your own exception Found 4 errors. ``` Some potential changes examples ```diff if not self.service: - raise Exception("The 'service' should be initialized before!") + raise RuntimeError("The 'service' should be initialized before!") ``` ```diff try: from pandas.io import sql as psql except ImportError: - raise Exception( + raise AirflowOptionalProviderFeatureException( "pandas library not installed, run: pip install " "'apache-airflow-providers-common-sql[pandas]'." ) ``` > [!TIP] > Feel free to ask a suggestion/helps in slack channels `#contributors` or `#new-contributors` > [!NOTE] > It should not affect related tests but it would be nice to change `pytest.raises(Exception)` in related tests, > however it could be done in other tasks later on, e.g. when we turn on > [`B017` assert-raises-exception](https://docs.astral.sh/ruff/rules/assert-raises-exception/) > [!WARNING] > Please consider to make changes in the one provider in the time ## Provider [airbyte](https://github.com/apache/airflow/tree/main/airflow/providers/airbyte) - [ ] `airflow/providers/airbyte/hooks/airbyte.py` - [ ] `airflow/providers/airbyte/operators/airbyte.py` - [ ] `airflow/providers/airbyte/sensors/airbyte.py` ## Provider [alibaba](https://github.com/apache/airflow/tree/main/airflow/providers/alibaba) - [ ] `airflow/providers/alibaba/cloud/hooks/oss.py` ## Provider [amazon](https://github.com/apache/airflow/tree/main/airflow/providers/amazon) - [ ] `airflow/providers/amazon/aws/operators/athena.py` - [ ] `airflow/providers/amazon/aws/operators/emr.py` ## Provider [apache.beam](https://github.com/apache/airflow/tree/main/airflow/providers/apache/beam) - [ ] `airflow/providers/apache/beam/hooks/beam.py` ## Provider [apache.cassandra](https://github.com/apache/airflow/tree/main/airflow/providers/apache/cassandra) - [ ] `airflow/providers/apache/cassandra/hooks/cassandra.py` ## Provider [apache.hdfs](https://github.com/apache/airflow/tree/main/airflow/providers/apache/hdfs) - [ ] `airflow/providers/apache/hdfs/hooks/hdfs.py` - [ ] `airflow/providers/apache/hdfs/sensors/hdfs.py` ## Provider [apache.hive](https://github.com/apache/airflow/tree/main/airflow/providers/apache/hive) - [ ] `airflow/providers/apache/hive/hooks/hive.py` ## Provider [cncf.kubernetes](https://github.com/apache/airflow/tree/main/airflow/providers/cncf/kubernetes) - [ ] `airflow/providers/cncf/kubernetes/operators/pod.py` ## Provider [common.sql](https://github.com/apache/airflow/tree/main/airflow/providers/common/sql) - [ ] `airflow/providers/common/sql/hooks/sql.py` ## Provider [docker](https://github.com/apache/airflow/tree/main/airflow/providers/docker) - [ ] `airflow/providers/docker/operators/docker_swarm.py` ## Provider [fab](https://github.com/apache/airflow/tree/main/airflow/providers/fab) - [ ] `airflow/providers/fab/auth_manager/fab_auth_manager.py` - [ ] `airflow/providers/fab/auth_manager/security_manager/override.py` ## Provider [google](https://github.com/apache/airflow/tree/main/airflow/providers/google) - [ ] `airflow/providers/google/cloud/hooks/bigquery.py` - [ ] `airflow/providers/google/cloud/hooks/dataflow.py` - [ ] `airflow/providers/google/cloud/hooks/dataproc.py` - [ ] `airflow/providers/google/cloud/operators/dataproc.py` - [ ] `airflow/providers/google/leveldb/hooks/leveldb.py` ## Provider [imap](https://github.com/apache/airflow/tree/main/airflow/providers/imap) - [ ] `airflow/providers/imap/hooks/imap.py` ## Provider [microsoft.azure](https://github.com/apache/airflow/tree/main/airflow/providers/microsoft/azure) - [ ] `airflow/providers/microsoft/azure/operators/synapse.py` ## Provider [openlineage](https://github.com/apache/airflow/tree/main/airflow/providers/openlineage) - [ ] `airflow/providers/openlineage/utils/utils.py` ### Committer - [X] I acknowledge that I am a maintainer/committer of the Apache Airflow project. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
