mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 17:23:36 +02:00
jw.pkg.lib: Don't log {e}
Don't log an Exception as {e} but as str(e) producing nicer output.
Or as repr(e) if a backtrace is requested, because to people who can
read backtraces, type info might be of interest. Also, remove
pointless time stamps, those belong into the logging framework.
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
78d49edfeb
commit
7eb15f2477
3 changed files with 5 additions and 11 deletions
|
|
@ -116,10 +116,7 @@ class App: # export
|
||||||
try:
|
try:
|
||||||
ret = await self._run(self.__args)
|
ret = await self._run(self.__args)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if hasattr(e, 'message'):
|
log(ERR, repr(e) if self.__back_trace else str(e))
|
||||||
log(ERR, e.message)
|
|
||||||
else:
|
|
||||||
log(ERR, f'Exception: {type(e)}: {e}')
|
|
||||||
exit_status = 1
|
exit_status = 1
|
||||||
if self.__back_trace:
|
if self.__back_trace:
|
||||||
raise
|
raise
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ class Cmd(abc.ABC): # export
|
||||||
self.__children.append(cmd)
|
self.__children.append(cmd)
|
||||||
assert len(self.__children) == len(self.__child_classes)
|
assert len(self.__children) == len(self.__child_classes)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
cmds.dump(ERR, f"Failed to add subcommands ({e})")
|
cmds.dump(ERR, f"Failed to add subcommands ({str(e)})")
|
||||||
raise
|
raise
|
||||||
return
|
return
|
||||||
raise Exception(f'Tried to add sub-commands of unknown type {type(cmds)}')
|
raise Exception(f'Tried to add sub-commands of unknown type {type(cmds)}')
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ def pretty_cmd(cmd: list[str], wd=None):
|
||||||
if token.find(' ') != -1:
|
if token.find(' ') != -1:
|
||||||
token = '"' + token + '"'
|
token = '"' + token + '"'
|
||||||
tokens.append(token)
|
tokens.append(token)
|
||||||
ret = ' '.join(tokens)
|
ret = '>' + ' '.join(tokens) + '<'
|
||||||
if wd is not None:
|
if wd is not None:
|
||||||
ret += f' in {wd}'
|
ret += f' in {wd}'
|
||||||
return ret
|
return ret
|
||||||
|
|
@ -57,10 +57,7 @@ async def run_cmd(
|
||||||
|
|
||||||
def __check_exit_code(code):
|
def __check_exit_code(code):
|
||||||
if code != 0 and (throw or verbose):
|
if code != 0 and (throw or verbose):
|
||||||
msg = (
|
msg = f'Command returned error {code}: {pretty_cmd(args, wd)}'
|
||||||
time.strftime("%Y-%m-%d %H:%M")
|
|
||||||
+ f': Command returned error {code}: "{pretty_cmd(args, wd)}"'
|
|
||||||
)
|
|
||||||
if verbose:
|
if verbose:
|
||||||
__log(ERR, msg)
|
__log(ERR, msg)
|
||||||
if throw:
|
if throw:
|
||||||
|
|
@ -184,7 +181,7 @@ async def run_curl(args: list[str], parse_json: bool=True, wd=None, throw=None,
|
||||||
size = len(ret)
|
size = len(ret)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
print(f'Failed to parse {size} bytes output of command >{pretty_cmd(cmd, wd)}< ({e})', file=sys.stderr)
|
print(f'Failed to parse {size} bytes output of command >{pretty_cmd(cmd, wd)}< ({str(e)})', file=sys.stderr)
|
||||||
raise
|
raise
|
||||||
return ret
|
return ret
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue