Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cat-log list-dir mode: fail gracefully #6511

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading