mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-01-28 18:15:45 +08:00
better pcommandbatch error handling
This commit is contained in:
parent
85fcac10bb
commit
cdd942ea5a
1
.idea/dictionaries/ericf.xml
generated
1
.idea/dictionaries/ericf.xml
generated
@ -1675,6 +1675,7 @@
|
||||
<w>loginid</w>
|
||||
<w>logintoken</w>
|
||||
<w>logitech</w>
|
||||
<w>logpath</w>
|
||||
<w>logput</w>
|
||||
<w>loofa</w>
|
||||
<w>loosey</w>
|
||||
|
||||
@ -204,9 +204,7 @@ def is_batch() -> bool:
|
||||
return _g_batch_server_mode
|
||||
|
||||
|
||||
def run_client_pcommand(
|
||||
args: list[str], log_path: str, isatty: bool
|
||||
) -> tuple[int, str]:
|
||||
def run_client_pcommand(args: list[str], isatty: bool) -> tuple[int, str]:
|
||||
"""Call a pcommand function when running as a batch server."""
|
||||
assert _g_batch_server_mode
|
||||
assert _g_thread_local_storage is not None
|
||||
@ -222,20 +220,15 @@ def run_client_pcommand(
|
||||
_g_thread_local_storage.argv = args
|
||||
_g_thread_local_storage.isatty = isatty
|
||||
|
||||
# Run the command.
|
||||
# Run the command. This may return an explicit code or may throw an
|
||||
# exception.
|
||||
resultcode: int = _run_pcommand(args)
|
||||
|
||||
# Return the result code and any output the command provided.
|
||||
output = getattr(_g_thread_local_storage, 'output', '')
|
||||
|
||||
# Handle error result-codes consistently with exceptions.
|
||||
if resultcode != 0:
|
||||
if output:
|
||||
output += '\n'
|
||||
output += (
|
||||
f'Error: pcommandbatch command failed: {args}.'
|
||||
f" For more info, see '{log_path}', or rerun with"
|
||||
' env var BA_PCOMMANDBATCH_DISABLE=1 to see all output here.\n'
|
||||
)
|
||||
raise RuntimeError(f'client pcommand returned error code {resultcode}.')
|
||||
|
||||
output = getattr(_g_thread_local_storage, 'output', '')
|
||||
|
||||
assert isinstance(output, str)
|
||||
return (resultcode, output)
|
||||
|
||||
@ -333,14 +333,7 @@ class Server:
|
||||
output,
|
||||
) = await asyncio.get_running_loop().run_in_executor(
|
||||
None,
|
||||
lambda: run_client_pcommand(
|
||||
argv,
|
||||
# Show log file path relative to project.
|
||||
self._worker_log_file_path.removeprefix(
|
||||
f'{self._project_dir}/'
|
||||
),
|
||||
isatty,
|
||||
),
|
||||
lambda: run_client_pcommand(argv, isatty),
|
||||
)
|
||||
if VERBOSE:
|
||||
print(
|
||||
@ -359,7 +352,15 @@ class Server:
|
||||
file=sys.stderr,
|
||||
)
|
||||
resultcode = 1
|
||||
output = ''
|
||||
logpath = self._worker_log_file_path.removeprefix(
|
||||
f'{self._project_dir}/'
|
||||
)
|
||||
output = (
|
||||
f'Error: pcommandbatch command failed: {argv}.'
|
||||
f" For more info, see '{logpath}', or rerun with"
|
||||
' env var BA_PCOMMANDBATCH_DISABLE=1 to see'
|
||||
' all output here.\n'
|
||||
)
|
||||
|
||||
writer.write(json.dumps({'r': resultcode, 'o': output}).encode())
|
||||
writer.close()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user