mirror of
https://github.com/RYDE-WORK/ballistica.git
synced 2026-02-06 23:59:18 +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>loginid</w>
|
||||||
<w>logintoken</w>
|
<w>logintoken</w>
|
||||||
<w>logitech</w>
|
<w>logitech</w>
|
||||||
|
<w>logpath</w>
|
||||||
<w>logput</w>
|
<w>logput</w>
|
||||||
<w>loofa</w>
|
<w>loofa</w>
|
||||||
<w>loosey</w>
|
<w>loosey</w>
|
||||||
|
|||||||
@ -204,9 +204,7 @@ def is_batch() -> bool:
|
|||||||
return _g_batch_server_mode
|
return _g_batch_server_mode
|
||||||
|
|
||||||
|
|
||||||
def run_client_pcommand(
|
def run_client_pcommand(args: list[str], isatty: bool) -> tuple[int, str]:
|
||||||
args: list[str], log_path: str, isatty: bool
|
|
||||||
) -> tuple[int, str]:
|
|
||||||
"""Call a pcommand function when running as a batch server."""
|
"""Call a pcommand function when running as a batch server."""
|
||||||
assert _g_batch_server_mode
|
assert _g_batch_server_mode
|
||||||
assert _g_thread_local_storage is not None
|
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.argv = args
|
||||||
_g_thread_local_storage.isatty = isatty
|
_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)
|
resultcode: int = _run_pcommand(args)
|
||||||
|
|
||||||
# Return the result code and any output the command provided.
|
# Handle error result-codes consistently with exceptions.
|
||||||
output = getattr(_g_thread_local_storage, 'output', '')
|
|
||||||
|
|
||||||
if resultcode != 0:
|
if resultcode != 0:
|
||||||
if output:
|
raise RuntimeError(f'client pcommand returned error code {resultcode}.')
|
||||||
output += '\n'
|
|
||||||
output += (
|
output = getattr(_g_thread_local_storage, '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'
|
|
||||||
)
|
|
||||||
|
|
||||||
assert isinstance(output, str)
|
assert isinstance(output, str)
|
||||||
return (resultcode, output)
|
return (resultcode, output)
|
||||||
|
|||||||
@ -333,14 +333,7 @@ class Server:
|
|||||||
output,
|
output,
|
||||||
) = await asyncio.get_running_loop().run_in_executor(
|
) = await asyncio.get_running_loop().run_in_executor(
|
||||||
None,
|
None,
|
||||||
lambda: run_client_pcommand(
|
lambda: run_client_pcommand(argv, isatty),
|
||||||
argv,
|
|
||||||
# Show log file path relative to project.
|
|
||||||
self._worker_log_file_path.removeprefix(
|
|
||||||
f'{self._project_dir}/'
|
|
||||||
),
|
|
||||||
isatty,
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
if VERBOSE:
|
if VERBOSE:
|
||||||
print(
|
print(
|
||||||
@ -359,7 +352,15 @@ class Server:
|
|||||||
file=sys.stderr,
|
file=sys.stderr,
|
||||||
)
|
)
|
||||||
resultcode = 1
|
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.write(json.dumps({'r': resultcode, 'o': output}).encode())
|
||||||
writer.close()
|
writer.close()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user