Repository navigation
Conversation
Registry.get() raises RuntimeError when connection_persistence.json names a protocol that is missing or no longer valid. Catch that during connector startup, log a warning, and continue as if nothing was persisted. Co-authored-by: Miixms <Miixms99@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #33.
Problem
VPNConnector._get_current_connection()usesif protocol := self._registry.get(...), expectingNonewhen the persisted protocol has no valid implementation.Registry.get()raisesRuntimeErrorinstead (proton/vpn/core/registry.py).initialize_state()then crashes whenconnection_persistence.jsonnames a protocol that is not registered or whosevalidate()returns false, such as a leftoverprotun-smartconnection in snap/flatpak or on older NetworkManager.Reproduce
connection_persistence.jsonpointing atprotun-smart.validate()is false.Result:
RuntimeError: No valid implementation found for protun-smart. Expected initial state:Disconnected.Change
Catch that
RuntimeErrorin_get_current_connection(), log a warning, and returnNone. Startup staysDisconnected, as for a missing or corrupt persistence file. The file is left on disk, matching the corrupt-file path.Registry.get()is unchanged:connect()and protun default selection depend on the exception.Testing
Environment: Linux, Python 3.12.3, pytest 9.2.0, pytest-asyncio 1.5.0. Protocols are stub
Registryclasses; no VPN is opened.Before the fix:
python3 -m pytest tests/python/core/test_vpnconnector_persistence.py --no-cov -q --tb=line[False]is not registered.[True]is registered withvalidate()false. Missing file, corrupt file, and a validwireguardpersistence passed.After the fix, the same command:
5 passed in 0.10s.Full suite:
python3 -m pytest --tb=line -q->637 passed, 1 failed. The failure istests/python/test_modules_exist.py::test_modules_exist(No module named proton.vpn.platform.protun). The public protun crate lacks this repo's pinned commit and does not compile here, so that module was not built. It is unrelated to this change.flake8on the two changed files exited 0. pylint has no project config;vpnconnector.pystill has only thetoo-many-positional-argumentsmessages already present onstable.AI assistance was used to write the change and run the commands above in the environment described; the outputs shown are the actual results.