linux-cli-community icon indicating copy to clipboard operation
linux-cli-community copied to clipboard

[BUG] Exception raised when keys are missing from pvpn-cli.cfg

Open kurczynski opened this issue 5 years ago • 0 comments

Describe the bug When keys are missing from the pvpn-cli.cfg a KeyError is raised. I'm guessing this happens because it's always assumed that these keys have been created during some previous action.

To Reproduce Steps to reproduce the behavior:

  1. Remove keys such as metadata or last_update_check from pvpn-cli.cfg.
  2. Run protonvpn refresh or protonvpn connect --fastest respectively.
  3. A KeyError is raised.

Expected behavior Although these values should exist in the config file, if they are missing for some reason it would be nice to have sensible default values instead of raising an exception.

Error Messages/Program Output/Log Messages (~/.pvpn-cli/pvpn-cli.log) stderr when running protonvpn connect --fastest with missing last_update_check:

Traceback (most recent call last):
  File "/usr/bin/protonvpn", line 11, in <module>
    load_entry_point('protonvpn-cli==2.2.4', 'console_scripts', 'protonvpn')()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 73, in main
    cli()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 116, in cli
    connection.fastest(protocol)
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/connection.py", line 165, in fastest
    openvpn_connect(fastest_server, protocol)
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/connection.py", line 538, in openvpn_connect
    check_update()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/utils.py", line 378, in check_update
    last_check = int(get_config_value("metadata", "last_update_check"))
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/utils.py", line 123, in get_config_value
    return config[group][key]
  File "/usr/lib64/python3.8/configparser.py", line 1254, in __getitem__
    raise KeyError(key)
KeyError: 'last_update_check'

stderr when running protonvpn refresh with missing metatdata:

Traceback (most recent call last):
  File "/usr/bin/protonvpn", line 11, in <module>
    load_entry_point('protonvpn-cli==2.2.4', 'console_scripts', 'protonvpn')()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 73, in main
    cli()
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/cli.py", line 146, in cli
    pull_server_data(force=True)
  File "/usr/lib/python3.8/site-packages/protonvpn_cli/utils.py", line 90, in pull_server_data
    config["metadata"]["last_api_pull"] = str(int(time.time()))
  File "/usr/lib64/python3.8/configparser.py", line 960, in __getitem__
    raise KeyError(key)
KeyError: 'metadata'

Desktop (please complete the following information):

  • OS: Fedora 32
  • Python Version: 3.8.5
  • ProtonVPN-CLI Version: 2.2.4

kurczynski avatar Aug 13 '20 04:08 kurczynski