From 9fd28d2eed688578b7b90a3cd310773cc3f58d0a Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Tue, 8 Jun 2021 11:43:55 -0700 Subject: [PATCH] Fix error handling to error loudly when Borg gets killed due to running out of memory (#423)! --- NEWS | 1 + borgmatic/execute.py | 2 +- tests/unit/test_execute.py | 5 +++++ 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index 87f7fe3..60fc55f 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,7 @@ * #390: Add link to Hetzner storage offering from the documentation. * #398: Clarify canonical home of borgmatic in documentation. * #406: Clarify that spaces in path names should not be backslashed in path names. + * #423: Fix error handling to error loudly when Borg gets killed due to running out of memory! * Fix build so as not to attempt to build and push documentation for a non-master branch. * "Fix" build failure with Alpine Edge by switching from Edge to Alpine 3.13. * Move #borgmatic IRC channel from Freenode to Libera Chat due to Freenode takeover drama. diff --git a/borgmatic/execute.py b/borgmatic/execute.py index 6f5e56b..95a8f6c 100644 --- a/borgmatic/execute.py +++ b/borgmatic/execute.py @@ -23,7 +23,7 @@ def exit_code_indicates_error(process, exit_code, borg_local_path=None): command = process.args.split(' ') if isinstance(process.args, str) else process.args if borg_local_path and command[0] == borg_local_path: - return bool(exit_code >= BORG_ERROR_EXIT_CODE) + return bool(exit_code < 0 or exit_code >= BORG_ERROR_EXIT_CODE) return bool(exit_code != 0) diff --git a/tests/unit/test_execute.py b/tests/unit/test_execute.py index 97e197a..c747a94 100644 --- a/tests/unit/test_execute.py +++ b/tests/unit/test_execute.py @@ -21,6 +21,11 @@ from borgmatic import execute as module (flexmock(args=['grep']), 0, 'borg', False), (flexmock(args=['borg']), 0, 'borg', False), (flexmock(args=['borg1']), 0, 'borg1', False), + # -9 exit code occurs when child process get SIGKILLed. + (flexmock(args=['grep']), -9, None, True), + (flexmock(args=['grep']), -9, 'borg', True), + (flexmock(args=['borg']), -9, 'borg', True), + (flexmock(args=['borg1']), -9, 'borg1', True), (flexmock(args=['borg']), None, None, False), ), )