insanum / sncli

Simplenote CLI
MIT License
396 stars 34 forks source link

Better error message when .snclirc doesn't exist #74

Closed ericbrandwein closed 5 years ago

ericbrandwein commented 5 years ago

When running sncli for the first time, I got this error:

> sncli
Traceback (most recent call last):
  File "/usr/lib/python3.7/configparser.py", line 788, in get
    value = d[option]
  File "/usr/lib/python3.7/collections/__init__.py", line 914, in __getitem__
    return self.__missing__(key)            # support subclasses that define __missing__
  File "/usr/lib/python3.7/collections/__init__.py", line 906, in __missing__
    raise KeyError(key)
KeyError: 'cfg_sn_password_eval'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/bin/sncli", line 11, in <module>
    load_entry_point('sncli==0.3.0', 'console_scripts', 'sncli')()
  File "/usr/lib/python3.7/site-packages/simplenote_cli/sncli.py", line 1353, in main
    sncli(sync, verbose, config).gui(key)
  File "/usr/lib/python3.7/site-packages/simplenote_cli/sncli.py", line 18, in __init__
    self.config         = Config(config_file)
  File "/usr/lib/python3.7/site-packages/simplenote_cli/config.py", line 138, in __init__
    command = cp.get(cfg_sec, 'cfg_sn_password_eval', raw=True)
  File "/usr/lib/python3.7/configparser.py", line 791, in get
    raise NoOptionError(option, section)
configparser.NoOptionError: No option 'cfg_sn_password_eval' in section: 'sncli'

This happened because I didn't put a password in the configuration file. Maybe using a better error message, like "Configuration file $HOME/.sncli does not have a password set", or maybe prompting for the password to put on the configuration file, would make for a better experience for the user.

N0ury commented 5 years ago

+1

samuelallan72 commented 5 years ago

Thanks for the report! Looking into a solution now.

samuelallan72 commented 5 years ago

This is tricky, because config is loaded before logging is set up. Perhaps an absence of a config file, username, or password, should result in a print(<error message>) and sys.exit? Thoughts appreciated. :)

N0ury commented 5 years ago

This is a good solution. And as said @ericbrandwein, if password is missing, it would be nice to prompt for it. It's not necessary to log anything.

samuelallan72 commented 5 years ago

WIP pull request opened for feedback: #75

samuelallan72 commented 5 years ago

This can be marked as solved now that the above PR is merged