From b5f323ff07dc39cb917b36b0f0da42555df0330a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Fri, 3 May 2019 13:18:51 +0200 Subject: [PATCH] utils: capture and log phantomjs stderr (#32773) --- mandayejs/mandaye/utils.py | 5 +++-- tests/test_mandayejs.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mandayejs/mandaye/utils.py b/mandayejs/mandaye/utils.py index 73c128e..9d51f7a 100644 --- a/mandayejs/mandaye/utils.py +++ b/mandayejs/mandaye/utils.py @@ -37,7 +37,8 @@ def run(send_end, data, script): os.path.join(settings.BASE_DIR, 'mandayejs', script)], close_fds=True, stdin=subprocess.PIPE, - stdout=subprocess.PIPE + stdout=subprocess.PIPE, + stderr=subprocess.PIPE ) stdout, stderr = phantom.communicate(json.dumps(data)) @@ -49,7 +50,7 @@ def run(send_end, data, script): result = json.loads(stdout) except (ValueError,): result = {"result": "json_error"} - logger.error("invalid json: %s" % stdout) + logger.error("invalid json: %s (stderr: %s)", stdout, stderr) if result.get('stderr'): logger.warning(result['stderr']) diff --git a/tests/test_mandayejs.py b/tests/test_mandayejs.py index a7c0671..ef5f98c 100644 --- a/tests/test_mandayejs.py +++ b/tests/test_mandayejs.py @@ -100,7 +100,7 @@ def test_command_migrate_users(mocked_idps, command): @mock.patch('mandayejs.mandaye.utils.subprocess.Popen') @mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS) def test_phantom_invalid_json(mocked_popen, caplog, user_john): - expected_output = ('This is not a valid JSON', None) + expected_output = ('This is not a valid JSON', 'msg on stderr') mocked_popen.return_value = MockedPopen(expected_output=expected_output) UserCredentials.objects.create(user=user_john, @@ -119,7 +119,7 @@ def test_phantom_invalid_json(mocked_popen, caplog, user_john): for record in caplog.records: if record.levelname == 'ERROR': - assert record.message == 'invalid json: This is not a valid JSON' + assert record.message == 'invalid json: This is not a valid JSON (stderr: msg on stderr)' @mock.patch('mandayejs.mandaye.utils.subprocess.Popen')