Skip to content

Commit

Permalink
Merge pull request #6512 from cylc/8.3.x-sync
Browse files Browse the repository at this point in the history
🤖 Merge 8.3.x-sync into master
  • Loading branch information
oliver-sanders authored Dec 3, 2024
2 parents 9ff50f8 + a728b61 commit 1e3699a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions changes.d/6511.fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cat-log command list-dir mode: fail gracefully if directory not found.
8 changes: 6 additions & 2 deletions cylc/flow/scripts/cat_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,13 +261,17 @@ def view_log(
print(os.path.dirname(logpath))
return 0
if mode == 'list-dir':
for entry in sorted(os.listdir(os.path.dirname(logpath))):
dirname = os.path.dirname(logpath)
if not os.path.exists(dirname):
sys.stderr.write(f"Directory not found: {dirname}\n")
return 1
for entry in sorted(os.listdir(dirname)):
print(entry)
return 0
if not os.path.exists(logpath) and batchview_cmd is None:
# Note: batchview_cmd may not need to have access to logpath, so don't
# test for existence of path if it is set.
sys.stderr.write('file not found: %s\n' % logpath)
sys.stderr.write('File not found: %s\n' % logpath)
return 1
if prepend_path:
from cylc.flow.hostuserutil import get_host
Expand Down
18 changes: 17 additions & 1 deletion tests/integration/scripts/test_cat_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,22 @@ def test_bad_workflow2(run_dir, brokendir, capsys):
BAD_NAME
)
msg = (
f'file not found: {run_dir}'
f'File not found: {run_dir}'
'/NONEXISTENTWORKFLOWNAME/log/j\n')
assert capsys.readouterr().err == msg


def test_bad_task_dir(run_dir, brokendir, capsys):
"""Check a non existent job log dir in a valid workflow results in error.
"""
parser = cat_log_gop()
with pytest.raises(SystemExit, match='1'):
cat_log(
parser,
Options(parser)(mode='list-dir'),
BAD_NAME + "//1/foo"
)
msg = (
f'Directory not found: {run_dir}'
'/NONEXISTENTWORKFLOWNAME/log/job/1/foo/NN\n')
assert capsys.readouterr().err == msg

0 comments on commit 1e3699a

Please sign in to comment.