You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Taragolis (via GitHub)" <gi...@apache.org> on 2024/04/05 06:36:07 UTC

[I] Fix remaining `TRY002` - raising Exception into the providers codebase [airflow]

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: commits-unsubscribe@airflow.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Fix remaining `TRY002` - raising `Exception` into the providers codebase [airflow]

Posted by "Taragolis (via GitHub)" <gi...@apache.org>.
Taragolis closed issue #38761: Fix remaining `TRY002` - raising `Exception` into the providers codebase
URL: https://github.com/apache/airflow/issues/38761


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [I] Fix remaining `TRY002` - raising `Exception` into the providers codebase [airflow]

Posted by "dondaum (via GitHub)" <gi...@apache.org>.
dondaum commented on issue #38761:
URL: https://github.com/apache/airflow/issues/38761#issuecomment-2039339839

   I would be happy to support here and take this one over.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org