Skip to content

Commit

Permalink
Add debug env var FTL_DEBUG
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew000 committed Dec 24, 2024
1 parent 0bac847 commit 51438bd
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/ftl_extract/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
)
IGNORE_KWARGS: Final[frozenset[str]] = frozenset()
DEFAULT_FTL_FILE: Final[Path] = Path("_default.ftl")
FTL_DEBUG_VAR_NAME: Final = "FTL_DEBUG"
22 changes: 18 additions & 4 deletions src/ftl_extract/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
from __future__ import annotations

from os import environ
from pprint import pformat
from typing import TYPE_CHECKING

from ftl_extract.const import FTL_DEBUG_VAR_NAME
from ftl_extract.utils import to_json_no_span

if TYPE_CHECKING:
from pathlib import Path

Expand Down Expand Up @@ -31,10 +36,19 @@ def __init__(
) -> None:
self.current_translation = current_translation
self.new_translation = new_translation
super().__init__(
f"Translation {key!r} already exists with different elements: "
f"{self.current_translation} != {self.new_translation}",
)

if bool(environ.get(FTL_DEBUG_VAR_NAME, False)) is True:
super().__init__(
f"Translation {key!r} already exists with different elements:\n"
f"current_translation: "
f"{pformat(self.current_translation.to_json(fn=to_json_no_span))}\n!= "
f"new_translation: {pformat(self.new_translation.to_json(fn=to_json_no_span))}",
)
else:
super().__init__(
f"Translation {key!r} already exists with different elements: "
f"{self.current_translation} != {self.new_translation}",
)


class FTLExtractorCantFindReferenceError(FTLExtractorError):
Expand Down
2 changes: 1 addition & 1 deletion uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 51438bd

Please sign in to comment.