codeant-ai-for-open-source[bot] commented on code in PR #41465:
URL: https://github.com/apache/superset/pull/41465#discussion_r3486069924
##########
scripts/translations/build_translation_index.py:
##########
@@ -86,7 +86,17 @@ def build_index(translations_dir: Path) -> dict[str, Any]:
for lang in langs:
po_path = translations_dir / lang / "LC_MESSAGES" / "messages.po"
- cat = polib.pofile(str(po_path))
+ try:
+ cat = polib.pofile(str(po_path))
+ except OSError as exc:
Review Comment:
**Suggestion:** The new error handling is too narrow: `polib.pofile()` can
also fail with decode/parsing exceptions that are not `OSError` (for example
`UnicodeDecodeError` on malformed catalog encoding), so a single bad catalog
can still crash the whole index build. Broaden the caught exception set for
parse/read failures so unparseable files are consistently skipped as intended.
[incomplete implementation]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ `build_translation_index.py` crashes on certain malformed catalogs.
- ❌ `translation_index.json` not written, blocking backfill tooling.
- ⚠️ AI translation backfill in `backfill_po.py` cannot run.
- ⚠️ Translation maintenance workflow disrupted when any catalog corrupt.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Run the translation index builder entry point in
`scripts/translations/build_translation_index.py:128-163` via `python
scripts/translations/build_translation_index.py` (this calls `main()`, which
in turn calls
`build_index(TRANSLATIONS_DIR)` at line 151).
2. Ensure there is at least one language catalog under
`superset/translations/<lang>/LC_MESSAGES/messages.po` with malformed
encoding or
structure that causes `polib.pofile()` to raise a non-`OSError` exception
(for example a
`UnicodeDecodeError` or `ValueError` during parse); `build_index()` iterates
these at
lines 80-88 and reaches the problematic `po_path`.
3. When execution reaches `build_index()` at
`scripts/translations/build_translation_index.py:76-125`, it enters the loop
at line 87,
computes `po_path` at line 88, and calls `cat = polib.pofile(str(po_path))`
inside the
`try` block at line 90.
4. Because the malformed catalog triggers a non-`OSError` exception type from
`polib.pofile()` (e.g. `UnicodeDecodeError` which inherits from
`ValueError`, not
`OSError`), the `except OSError as exc:` block at line 91 does not catch it;
the exception
propagates out of `build_index()`, causing the entire script
`build_translation_index.py`
to terminate and preventing `translation_index.json` from being written,
despite other
languages being parseable.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=22343e3526ba4bc7a3114cc73c230a90&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=22343e3526ba4bc7a3114cc73c230a90&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** scripts/translations/build_translation_index.py
**Line:** 89:91
**Comment:**
*Incomplete Implementation: The new error handling is too narrow:
`polib.pofile()` can also fail with decode/parsing exceptions that are not
`OSError` (for example `UnicodeDecodeError` on malformed catalog encoding), so
a single bad catalog can still crash the whole index build. Broaden the caught
exception set for parse/read failures so unparseable files are consistently
skipped as intended.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41465&comment_hash=19405f8e6f3ef7725b799c6805197554606b11ea9db0ee4a3e5cd2b365f3d0ee&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F41465&comment_hash=19405f8e6f3ef7725b799c6805197554606b11ea9db0ee4a3e5cd2b365f3d0ee&reaction=dislike'>👎</a>
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]