Skip to content

Commit

Permalink
Fix #177 - Remove tracebacks from logs for mirror IO errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
mxsasha committed Feb 6, 2019
1 parent 0a2c298 commit af2ad1d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 4 additions & 0 deletions irrd/mirroring/mirror_runners_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ def run(self) -> None:
self.update_stream_runner.run(serial_newest_seen, database_handler=self.database_handler)

self.database_handler.commit()
except OSError as ose:
# I/O errors can occur and should not log a full traceback (#177)
logger.error(f'An error occurred while attempting a mirror update or initial import '
f'for {self.source}: {ose}')
except Exception as exc:
logger.error(f'An exception occurred while attempting a mirror update or initial import '
f'for {self.source}: {exc}', exc_info=exc)
Expand Down
22 changes: 21 additions & 1 deletion irrd/mirroring/tests/test_mirror_runners_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,26 @@ def test_update_stream_call(self, monkeypatch, config_override):
assert mock_stream_runner.mock_calls[0][0] == 'run'
assert mock_stream_runner.mock_calls[0][1] == (424242,)

def test_exception_handling(self, monkeypatch, caplog):
def test_io_exception_handling(self, monkeypatch, caplog):
mock_dh = Mock()
mock_dq = Mock()
mock_full_import_runner = Mock()

monkeypatch.setattr('irrd.mirroring.mirror_runners_import.DatabaseHandler', lambda: mock_dh)
monkeypatch.setattr('irrd.mirroring.mirror_runners_import.DatabaseStatusQuery', lambda: mock_dq)
monkeypatch.setattr('irrd.mirroring.mirror_runners_import.MirrorFullImportRunner', lambda source: mock_full_import_runner)
mock_full_import_runner.run = Mock(side_effect=ConnectionResetError('test-error'))

mock_dh.execute_query = lambda q: iter([{'serial_newest_seen': 424242, 'force_reload': False}])
runner = MirrorImportUpdateRunner(source='TEST')
runner.run()

assert flatten_mock_calls(mock_dh) == [['close', (), {}]]
assert 'An error occurred while attempting a mirror update or initial import for TEST' in caplog.text
assert 'test-error' in caplog.text
assert 'Traceback' not in caplog.text

def test_unexpected_exception_handling(self, monkeypatch, caplog):
mock_dh = Mock()
mock_dq = Mock()
mock_full_import_runner = Mock()
Expand All @@ -98,6 +117,7 @@ def test_exception_handling(self, monkeypatch, caplog):
assert flatten_mock_calls(mock_dh) == [['close', (), {}]]
assert 'An exception occurred while attempting a mirror update or initial import for TEST' in caplog.text
assert 'test-error' in caplog.text
assert 'Traceback' in caplog.text


class TestMirrorFullImportRunner:
Expand Down

0 comments on commit af2ad1d

Please sign in to comment.