mirror of
https://github.com/pre-commit/pre-commit.git
synced 2026-01-24 09:49:12 -06:00
Don't crash on un-stringable exceptions
This commit is contained in:
@@ -6,6 +6,7 @@ from unittest import mock
|
||||
import pytest
|
||||
|
||||
from pre_commit import error_handler
|
||||
from pre_commit.util import CalledProcessError
|
||||
from testing.util import cmd_output_mocked_pre_commit_home
|
||||
|
||||
|
||||
@@ -135,6 +136,22 @@ def test_error_handler_non_ascii_exception(mock_store_dir):
|
||||
raise ValueError('☃')
|
||||
|
||||
|
||||
def test_error_handler_non_utf8_exception(mock_store_dir):
|
||||
with pytest.raises(SystemExit):
|
||||
with error_handler.error_handler():
|
||||
raise CalledProcessError(1, ('exe',), 0, b'error: \xa0\xe1', b'')
|
||||
|
||||
|
||||
def test_error_handler_non_stringable_exception(mock_store_dir):
|
||||
class C(Exception):
|
||||
def __str__(self):
|
||||
raise RuntimeError('not today!')
|
||||
|
||||
with pytest.raises(SystemExit):
|
||||
with error_handler.error_handler():
|
||||
raise C()
|
||||
|
||||
|
||||
def test_error_handler_no_tty(tempdir_factory):
|
||||
pre_commit_home = tempdir_factory.get()
|
||||
ret, out, _ = cmd_output_mocked_pre_commit_home(
|
||||
|
||||
Reference in New Issue
Block a user