rjgoyln opened a new pull request, #73076:
URL: https://github.com/apache/airflow/pull/73076
## Summary
Exception constructors do not interpolate. `raise
AirflowException("TaskInstance %s is not found", ti.task_id)` reads like a
logger call, but `Exception.__init__` only stores its arguments — the message
keeps its literal `%s`, and the identifier it exists to carry sits beside it in
`args`. Where the exception forwards just the message to `super()`, as
google.api_core's `GoogleAPICallError` family does, that identifier is dropped
from the message entirely.
There are 44 of these on main across seven distributions, enough for the
shape to read as house style to anyone reviewing a new one. Nothing in ruff
covers it: `PLE1205`/`PLE1206` and `G001`/`G002` are logging-only, and `EM101`
does fire on these lines but objects to the string literal, so taking its
suggested fix leaves the bug in place.
## Change
- Add prek hook `check-no-new-exception-format-args`, subclassing
`AllowlistManager` beside `check-no-new-airflow-exceptions`.
- Flag a raise only when the placeholder count exactly equals the
trailing-argument count, counted as Python's own `%` operator would consume
them.
- Record the existing 44 occurrences, which this PR does not fix.
Detection walks the AST because the pattern routinely spans several lines.
The exact-count rule is what keeps the check quiet: ten or so call sites
already pass a literal message alongside unrelated positional parameters —
`TypeError("Could not parse hits.", response)`, SQLAlchemy's
`OperationalError(statement, params, orig)` — and anything looser flags all of
them.
---
##### Was generative AI tooling used to co-author this PR?
- [X] Yes — Claude Code (Opus 5)
Generated-by: Claude Code (Opus 5) following [the
guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#gen-ai-assisted-contributions)
--
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]