Skip to content

Success message with "→" crashes backup reporting on Windows #992

Closed

Description

@sub4biz

Problem

On Windows, the backup success message in export.py:82 contains → (U+2192), which cannot be encoded by Windows console encodings that lack this character, including at least cp1251 (Russian locale) and cp1252 (Western European locale).

This causes a UnicodeEncodeError inside the try block - caught by the outer except and reported as "backup failed" - even though shutil.copy2 already copied the files successfully. The backup works, but looks like it didn't.

Fix

Add sys.stdout.reconfigure(encoding='utf-8') at the top of backup_if_protected() to preserve the → symbol and ensure correct rendering on all platforms regardless of system locale.

Alternatively, replace → with -> on line 82 of export.py.

Environment

Windows 11, Russian locale (cp1251)
Python 3.13
graphifyy 0.8.16

Note

The UnicodeEncodeError is triggered specifically by the print on line 82 (success message), but the same issue would affect any print containing → or other non-cp1251/cp1252 characters on Windows. Using sys.stdout.reconfigure(encoding='utf-8') as a fix would cover all such cases in the codebase at once, rather than patching individual print statements.

Activity

  1. changed the title [-]backup_if_protected silently fails on Windows due to → in print statement[/-] [+]Success message with "→" crashes backup reporting on Windows[/+] on May 23, 2026
  2. safishamsi commented on May 23, 2026

    @safishamsi
    Member

    Fixed in v8 — replaced non-ASCII → with -> in all print statements in __main__.py. Ships in next release.

  3. sub4biz commented on May 30, 2026

    @sub4biz
    Author

    The bug is back in 0.8.26, this time in export.py rather than __main__.py.

    The previous fix replaced → in __main__.py, but missed export.py, line 89:

    print(f"[graphify] backed up {reason} graph ({copied} files) → {backup_dir.name}/")

    This UnicodeEncodeError is caught by the broad except Exception on line 91 - the same handler that catches real backup failures - so the backup is falsely reported as failed even though shutil.copy2 already finished successfully.

    Fixing symbols file by file doesn't scale - any future →, —, ✓, or emoji in any print() call across any module will hit the same issue on Windows.

    Suggested permanent fix - two lines at the top of main() in __main__.py:

    def main() -> None:
        if hasattr(sys.stdout, 'reconfigure'):
            sys.stdout.reconfigure(encoding='utf-8', errors='replace')
        if hasattr(sys.stderr, 'reconfigure'):
            sys.stderr.reconfigure(encoding='utf-8', errors='replace')
        ...

    This covers all modules in one place and never needs to be repeated. reconfigure() is the official Python 3.7+ API for this; errors='replace' degrades gracefully on legacy consoles instead of crashing.

    Environment: Windows 11, Python 3.13, graphify 0.8.26, PowerShell.

  4. safishamsi commented on May 30, 2026

    @safishamsi
    Member

    Fixed in commit 31a608f, shipping in the next release.

    Two-pronged fix:

    1. sys.stdout.reconfigure(encoding='utf-8', errors='replace') — added at the very top of main() before any output. On Windows consoles with cp1252/cp1251 encoding, this switches the stream to UTF-8 and falls back to ? for any character that still can't render, so nothing crashes.

    2. Symbol cleanup — replaced every → and — in print() calls across __main__.py, export.py, and prs.py with -> and -. Belt-and-suspenders: if reconfigure ever isn't available (e.g. PYTHONIOENCODING overrides, output redirected to a file opened in binary mode), the output is still safe ASCII.

    Full test suite passes (1483 passed, 0 failures).

  5. safishamsi commented on May 30, 2026

    @safishamsi
    Member

    @sub4biz changes are committed, will bump the package version and push to PyPI shortly so you can pip install the fix.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions