khard icon indicating copy to clipboard operation
khard copied to clipboard

Enhancement: Short error messages instead of traceback

Open bharatvaj opened this issue 2 years ago • 0 comments

This was what I got when I first started khard for the first time. Instead of a traceback, it would be better if it showed only the error message.

Traceback (most recent call last):
  File "/usr/bin/khard", line 33, in <module>
    sys.exit(load_entry_point('khard==0.17.0', 'console_scripts', 'khard')())
  File "/usr/lib/python3.9/site-packages/khard/khard.py", line 1068, in main
    args, conf = cli.init(argv)
  File "/usr/lib/python3.9/site-packages/khard/cli.py", line 513, in init
    args, conf = parse_args(argv)
  File "/usr/lib/python3.9/site-packages/khard/cli.py", line 400, in parse_args
    config = Config(args.config)
  File "/usr/lib/python3.9/site-packages/khard/config.py", line 91, in __init__
    config = self._load_config_file(config_file)
  File "/usr/lib/python3.9/site-packages/khard/config.py", line 111, in _load_config_file
    return configobj.ConfigObj(
  File "/usr/lib/python3.9/site-packages/configobj/__init__.py", line 1205, in __init__
    self._load(infile, configspec)
  File "/usr/lib/python3.9/site-packages/configobj/__init__.py", line 1220, in _load
    raise IOError('Config file not found: "%s".' % self.filename)
OSError: Config file not found: "/home/neet/.config/khard/khard.conf".

This is when I tried the example khard.conf file in README without actually having the required files

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/khard/config.py", line 174, in init_address_books
    "tmp", [VdirAddressBook(name, section[name]['path'], **kwargs)
  File "/usr/lib/python3.9/site-packages/khard/config.py", line 174, in <listcomp>
    "tmp", [VdirAddressBook(name, section[name]['path'], **kwargs)
  File "/usr/lib/python3.9/site-packages/khard/address_book.py", line 168, in __init__
    raise FileNotFoundError("[Errno 2] The path {} to the address book"
FileNotFoundError: [Errno 2] The path ~/.contacts/family/ to the address book family does not exist.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/khard", line 33, in <module>
    sys.exit(load_entry_point('khard==0.17.0', 'console_scripts', 'khard')())
  File "/usr/lib/python3.9/site-packages/khard/khard.py", line 1068, in main
    args, conf = cli.init(argv)
  File "/usr/lib/python3.9/site-packages/khard/cli.py", line 521, in init
    return args, merge_args_into_config(args, conf)
  File "/usr/lib/python3.9/site-packages/khard/cli.py", line 497, in merge_args_into_config
    config.init_address_books()
  File "/usr/lib/python3.9/site-packages/khard/config.py", line 177, in init_address_books
    raise ConfigError(str(err))
khard.config.ConfigError: [Errno 2] The path ~/.contacts/family/ to the address book family does not exist.

Although these messages might be helpful for developers. It creates a bad user experience. Maybe show traces only on --verbose or --debug option?

bharatvaj avatar Jul 18 '21 13:07 bharatvaj