Lee-W commented on code in PR #55416:
URL: https://github.com/apache/airflow/pull/55416#discussion_r3043819090


##########
scripts/ci/prek/check_new_airflow_exception_usage.py:
##########
@@ -0,0 +1,227 @@
+#!/usr/bin/env python
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# /// script
+# requires-python = ">=3.10"
+# dependencies = [
+#   "rich>=13.0.0",
+# ]
+# ///
+"""Check that no new ``raise AirflowException`` usages are introduced.
+
+All *existing* usages are recorded in ``known_airflow_exceptions.txt`` next to
+this script (one ``relative/path::stripped_raise_line`` entry per line).  Any
+``raise AirflowException`` found in a checked file that is **not** present in
+that list is treated as a violation – use a dedicated exception class instead.
+
+Modes
+-----
+Default (files passed by prek/pre-commit):
+    Check only the supplied files; fail on any unlisted usage.
+
+``--all-files``:
+    Walk the whole repository and check every ``.py`` file.
+
+``--cleanup``:
+    Remove stale entries from the allowlist (entries whose exception no longer
+    exists in the corresponding source file). Safe to run at any time; does
+    not add new entries.
+
+``--generate``:
+    Scan the whole repository and *rebuild* the allowlist from scratch.
+    Intended for the initial setup or after a large-scale clean-up sprint.
+"""
+
+from __future__ import annotations
+
+import argparse
+import re
+from pathlib import Path
+
+from rich.console import Console
+from rich.panel import Panel
+
+console = Console()
+
+REPO_ROOT = Path(__file__).parents[3]
+
+# Match lines that actually raise AirflowException. Comment filtering is done
+# in _raise_lines() by skipping lines whose stripped form starts with "#".
+_RAISE_RE = re.compile(r"raise\s+AirflowException\b")

Review Comment:
   I guess not? At least, it's not what I proposed back then. The reason why I 
think we should not use it is that `AirflowException` is broad and provides no 
extra information, but subclasses might.



-- 
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]

Reply via email to