lib.App: Fix crash on invalid log options
The --log-level and --log-flags options are added without a type converter, so argparse never validates their values. _build_parser() then hands the raw string to set_log_level() and set_log_flags() during its first parse, and an unparseable value such as "INVALID" crashes __init__() with a raw ValueError traceback instead of a usage error. Pass type = parse_log_level() and type = parse_log_flags() when adding the options, so that argparse reports invalid values with the standard usage error and exit status 2. argparse only applies the converter to command-line strings, so the int and LogFlag defaults are unaffected. Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v0.84.2 Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
25fc4d89f7
commit
8c47726a8d
1 changed files with 8 additions and 2 deletions
|
|
@ -35,10 +35,16 @@ class App: # export
|
|||
|
||||
def _add_arguments(self, parser: ArgumentParser) -> None:
|
||||
self.__parser.add_argument(
|
||||
'--log-flags', help = 'Log flags', default = self.__default_log_flags
|
||||
'--log-flags',
|
||||
help = 'Log flags',
|
||||
default = self.__default_log_flags,
|
||||
type = parse_log_flags,
|
||||
)
|
||||
self.__parser.add_argument(
|
||||
'--log-level', help = 'Log level', default = self.__default_log_level
|
||||
'--log-level',
|
||||
help = 'Log level',
|
||||
default = self.__default_log_level,
|
||||
type = parse_log_level,
|
||||
)
|
||||
self.__parser.add_argument(
|
||||
'--log-file', help = 'Log file', default = self.__default_log_file
|
||||
|
|
|
|||
Loading…
Reference in a new issue