Skip to content

Commit

Permalink
Raise useful error for cat-log failure when listing log files
Browse files Browse the repository at this point in the history
  • Loading branch information
MetRonnie committed Jun 24, 2024
1 parent d8756e6 commit 991f859
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions cylc/uiserver/resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ async def cat_log(cls, id_: Tokens, log, info, file=None):
yield {'connected': False}

@classmethod
async def cat_log_files(cls, id_: Tokens):
async def cat_log_files(cls, id_: Tokens, log: 'Logger') -> List[str]:
"""Calls cat log to get list of available log files.
Note kept separate from the cat_log method above as this is a one off
Expand All @@ -438,22 +438,26 @@ async def cat_log_files(cls, id_: Tokens):
file checking.
"""
cmd: List[str] = ['cylc', 'cat-log', '-m', 'l', '-o', id_.id]
log.debug(f"$ {' '.join(cmd)}")
proc_job = await asyncio.subprocess.create_subprocess_exec(
*cmd,
stdout=asyncio.subprocess.PIPE,
stderr=asyncio.subprocess.PIPE,
)
# wait for proc to finish
await proc_job.wait()
ret_code = await proc_job.wait()

# MOTD returned in stderr, no use in returning
out_job, _ = await proc_job.communicate()
if out_job:
out, err = await proc_job.communicate()
if ret_code:
raise Exception(
f"Command failed ({ret_code}): {' '.join(cmd)}\n{err.decode()}"
)
if out:
return sorted(
# return the log files in reverse sort order
# this means that the most recent log file rotations
# will be at the top of the list
out_job.decode().splitlines(),
out.decode().splitlines(),
reverse=True,
)
else:
Expand Down Expand Up @@ -569,7 +573,7 @@ async def query_service(
self,
id_: Tokens,
):
return await Services.cat_log_files(id_)
return await Services.cat_log_files(id_, self.log)


def kill_process_tree(
Expand Down

0 comments on commit 991f859

Please sign in to comment.