Skip to content

Commit 058da5f

Browse files
authored
Report Black version on internal error (#4457)
1 parent 98a580b commit 058da5f

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<!-- Changes to Black's terminal output and error messages -->
4949

5050
- Added Python target version information on parse error (#4378)
51+
- Add information about Black version to internal error messages (#4457)
5152

5253
### _Blackd_
5354

src/black/__init__.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,13 @@ def get_imports_from_children(children: List[LN]) -> Generator[str, None, None]:
15291529
return imports
15301530

15311531

1532+
def _black_info() -> str:
1533+
return (
1534+
f"Black {__version__} on "
1535+
f"Python ({platform.python_implementation()}) {platform.python_version()}"
1536+
)
1537+
1538+
15321539
def assert_equivalent(src: str, dst: str) -> None:
15331540
"""Raise AssertionError if `src` and `dst` aren't equivalent."""
15341541
try:
@@ -1546,7 +1553,7 @@ def assert_equivalent(src: str, dst: str) -> None:
15461553
except Exception as exc:
15471554
log = dump_to_file("".join(traceback.format_tb(exc.__traceback__)), dst)
15481555
raise ASTSafetyError(
1549-
f"INTERNAL ERROR: Black produced invalid code: {exc}. "
1556+
f"INTERNAL ERROR: {_black_info()} produced invalid code: {exc}. "
15501557
"Please report a bug on https://github.com/psf/black/issues. "
15511558
f"This invalid output might be helpful: {log}"
15521559
) from None
@@ -1556,9 +1563,9 @@ def assert_equivalent(src: str, dst: str) -> None:
15561563
if src_ast_str != dst_ast_str:
15571564
log = dump_to_file(diff(src_ast_str, dst_ast_str, "src", "dst"))
15581565
raise ASTSafetyError(
1559-
"INTERNAL ERROR: Black produced code that is not equivalent to the"
1560-
" source. Please report a bug on "
1561-
f"https://github.com/psf/black/issues. This diff might be helpful: {log}"
1566+
f"INTERNAL ERROR: {_black_info()} produced code that is not equivalent to"
1567+
" the source. Please report a bug on https://github.com/psf/black/issues."
1568+
f" This diff might be helpful: {log}"
15621569
) from None
15631570

15641571

@@ -1584,9 +1591,9 @@ def assert_stable(
15841591
diff(dst, newdst, "first pass", "second pass"),
15851592
)
15861593
raise AssertionError(
1587-
"INTERNAL ERROR: Black produced different code on the second pass of the"
1588-
" formatter. Please report a bug on https://github.com/psf/black/issues."
1589-
f" This diff might be helpful: {log}"
1594+
f"INTERNAL ERROR: {_black_info()} produced different code on the second"
1595+
" pass of the formatter. Please report a bug on"
1596+
f" https://github.com/psf/black/issues. This diff might be helpful: {log}"
15901597
) from None
15911598

15921599

0 commit comments

Comments
 (0)