Skip to content

INTERNAL ERROR crash; syntax error in log #5187

Closed

Description

@LukeShu

Describe the bug

Given particular inputs, Black crashes with an INTERNAL ERROR that I have not made sense of.

To Reproduce

Put this code in bug.py:

with open("bug.txt", "r", encoding="utf-8") as fh1:
    pass
# fmt: off
# fmt: on
# xxx
# fmt: off
# fmt: on
with open("bug.txt", "r", encoding="utf-8") as fh2:
    pass
def fn(str: str) -> float:
    match str:
        case _:
            pass

And run black bug.py.

The resulting error is:

error: cannot format bug.py: INTERNAL ERROR: Black 26.5.2.dev29+gb74b23013 on Python (CPython) 3.14.5 produced invalid code: unindent does not match any outer indentation level (<unknown>, line 10). Please report a bug on https://github.com/psf/black/issues.  This invalid output might be helpful: /run/user/1000/tmpdir/blk_tnip9iro.log

Oh no! 💥 💔 💥
1 file failed to reformat.

The .log file reads

  File "/home/lukeshu/Projects/sbc-harness/sbc-harness-hardware/build-aux/venv/lib/python3.14/site-packages/black/__init__.py", line 1652, in assert_equivalent
    dst_ast = parse_ast(dst)
  File "/home/lukeshu/Projects/sbc-harness/sbc-harness-hardware/build-aux/venv/lib/python3.14/site-packages/black/parsing.py", line 162, in parse_ast
    raise SyntaxError(first_error)
with open("bug.txt", "r", encoding="utf-8") as fh1:
    pass
# fmt: off
# fmt: on


# xxx
# fmt: off
# fmt: on
 with open("bug.txt", "r", encoding="utf-8") as fh2:
    pass


def fn(str: str) -> float:
    match str:
        case _:
            pass

Expected behavior

I expected Black to not crash.

Environment

Observed with both

$ black --version
black, 26.5.1 (compiled: no)
Python (CPython) 3.14.5

and

(venv) $ black --version
black, 26.5.2.dev29+gb74b23013 (compiled: no)
Python (CPython) 3.14.5

On Parabola GNU/Linux-libre (like Arch Linux).

Additional context

Running python bug.py returns without error---CPython does not encounter a syntax error. While minimizing the reproducer, I often got a case instead of an INTERNAL ERROR, Black told me I had invalid input with a syntax error, but I believed the input to be valid syntax.

Activity

  1. changed the title [-]INENTERNAL error[/-] [+]INTERNAL ERROR crash; syntax error in log[/+] on Jun 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions