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:
Jan Lindemann 2026-08-14 23:43:16 +02:00
commit 8c47726a8d
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -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