summaryrefslogtreecommitdiff
path: root/plugins/claude-security/scripts/lib/console.py
blob: b8a326357c765a266e91e7c6a82db4b3f354d331 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""The scripts' console output: undecodable path names and failed removals, printed readably."""

from __future__ import annotations

import io
import sys


def tolerate_undecodable_names() -> None:
    """Make stdout print an undecodable path name as escapes instead of raising."""
    if isinstance(sys.stdout, io.TextIOWrapper):
        sys.stdout.reconfigure(errors="backslashreplace")


def removal_failure_detail(error: OSError) -> object:
    """The operator-readable reason a tree removal failed."""
    return str(error) if error.strerror or not error.args else error.args[0]