diff --git a/src/ahriman/core/utils.py b/src/ahriman/core/utils.py index 50a7ec2e..03864790 100644 --- a/src/ahriman/core/utils.py +++ b/src/ahriman/core/utils.py @@ -136,7 +136,8 @@ def check_output(*args: str, exception: Exception | Callable[[int, list[str], st } | environment with subprocess.Popen(args, cwd=cwd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, - user=user, env=full_environment, text=True, encoding="utf8", bufsize=1) as process: + user=user, env=full_environment, text=True, encoding="utf8", errors="backslashreplace", + bufsize=1) as process: if input_data is not None: input_channel = get_io(process, "stdin") input_channel.write(input_data) diff --git a/tests/ahriman/core/test_utils.py b/tests/ahriman/core/test_utils.py index 1b65a90c..deafc04e 100644 --- a/tests/ahriman/core/test_utils.py +++ b/tests/ahriman/core/test_utils.py @@ -150,6 +150,13 @@ def test_check_output_empty_line(mocker: MockerFixture) -> None: logger_mock.assert_has_calls([MockCall(""), MockCall("hello")]) +def test_check_output_encoding_error(resource_path_root: Path) -> None: + """ + must correctly process unicode encoding error in command output + """ + assert check_output("cat", str(resource_path_root / "models" / "package_pacman-static_pkgbuild")) + + def test_check_user(repository_id: RepositoryId, mocker: MockerFixture) -> None: """ must check user correctly