linux-cli-community
linux-cli-community copied to clipboard
[BUG] Exception raised when keys are missing from pvpn-cli.cfg
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:
- Remove keys such as
metadataorlast_update_checkfrompvpn-cli.cfg. - Run
protonvpn refreshorprotonvpn connect --fastestrespectively. - A
KeyErroris 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