Skip to content

Commit

Permalink
Partial #7247 reply with full run_log in error exit in pkunit (#7291)
Browse files Browse the repository at this point in the history
  • Loading branch information
robnagler authored Oct 18, 2024
1 parent 0210c18 commit 2e9f88a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 24 deletions.
8 changes: 7 additions & 1 deletion sirepo/pkcli/job_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def _do_compute(msg, template):
stderr=run_log,
)

if pkconfig.in_dev_mode() and pkunit.is_test_run():
if _in_pkunit():
sys.stderr.write(pkio.read_text(msg.runDir.join(template_common.RUN_LOG)))
status = None
while True:
Expand Down Expand Up @@ -350,6 +350,10 @@ def _file_reply(resp, msg):
return job.ok_reply()


def _in_pkunit():
return pkconfig.in_dev_mode() and pkunit.is_test_run()


def _maybe_parse_user_alert(exception, error=None):
e = error or str(exception)
if isinstance(exception, sirepo.util.UserAlert):
Expand Down Expand Up @@ -392,6 +396,8 @@ def _success_exit():


def _parse_python_errors(text):
if _in_pkunit():
return text
m = re.search(
r"^Traceback .*?^\w*(?:Error|Exception):\s*(.*)",
text,
Expand Down
57 changes: 34 additions & 23 deletions tests/parse_error_log_test.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,45 @@
# -*- coding: utf-8 -*-
"""Parsing of an error run.log
:copyright: Copyright (c) 2019 RadiaSoft LLC. All Rights Reserved.
:license: http://www.apache.org/licenses/LICENSE-2.0.html
"""
from __future__ import absolute_import, division, print_function
import pytest

import os


def setup_module(module):
os.environ.update(
# Dev mode has to be false for these tests to pass
PYKERN_PKCONFIG_DEV_MODE="0",
# Need to set these manually when in non-dev-mode
SIREPO_COOKIE_IS_SECURE="0",
SIREPO_COOKIE_PRIVATE_KEY="MTIzNDU2Nzg5MDEyMzQ1Njc4OTAxMjM0NTY3ODkwMTI=",
SIREPO_SMTP_PASSWORD="dev",
SIREPO_SMTP_SERVER="dev",
SIREPO_SMTP_USER="dev",
)


def test_parse_python_errors():
from sirepo.pkcli import job_cmd
from pykern.pkunit import pkeq

err = """
Traceback (most recent call last):
File "/home/vagrant/src/radiasoft/sirepo/sirepo/pkcli/zgoubi.py", line 120, in _validate_estimate_output_file_size
'Estimated FAI output too large.\n'
AssertionError: Estimated FAI output too large.
Reduce particle count or number of runs,
or increase diagnostic interval.
"""
pkeq(
job_cmd._parse_python_errors(err),
"""Estimated FAI output too large.
Reduce particle count or number of runs,
or increase diagnostic interval.""",
)


def test_runError(fc):
from pykern import pkunit
from pykern.pkdebug import pkdc, pkdp, pkdlog
Expand All @@ -34,23 +65,3 @@ def test_runError(fc):
d = fc.sr_post("runStatus", d.nextRequest)
else:
pkunit.pkfail("Error never returned d={}", d)


def test_parse_python_errors():
from sirepo.pkcli import job_cmd
from pykern.pkunit import pkeq

err = """
Traceback (most recent call last):
File "/home/vagrant/src/radiasoft/sirepo/sirepo/pkcli/zgoubi.py", line 120, in _validate_estimate_output_file_size
'Estimated FAI output too large.\n'
AssertionError: Estimated FAI output too large.
Reduce particle count or number of runs,
or increase diagnostic interval.
"""
pkeq(
job_cmd._parse_python_errors(err),
"Estimated FAI output too large.\n"
"Reduce particle count or number of runs,\n"
"or increase diagnostic interval.",
)

0 comments on commit 2e9f88a

Please sign in to comment.