""" core/text.py — small text helpers shared by core/, conditions/ and flows/. Lives in core/ because core/ must not import from conditions/, pages/ or flows/, and all three need it (review of unit D, 2026-10-05: the condition runner, the Charge Summary and the flow each had their own copy). """ def first_line(value) -> str: """ The first non-blank line of `value`'s text, stripped. For an exception: Playwright's messages carry a whole call log after the first line, which is all a log line or a summary cell wants. An exception with an empty message gives its class name instead — a bare `str(exc).splitlines()[0]` raises IndexError on one. Any other empty value (an error string that came back blank) gives "". """ lines = str(value).strip().splitlines() if lines: return lines[0].strip() return type(value).__name__ if isinstance(value, BaseException) else ""