Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(store): warn on init instead of throw #3080

Merged
merged 1 commit into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion docker/credentials/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import shutil
import subprocess
import warnings

from . import constants
from . import errors
Expand All @@ -18,7 +19,7 @@ def __init__(self, program, environment=None):
self.exe = shutil.which(self.program)
self.environment = environment
if self.exe is None:
raise errors.InitializationError(
warnings.warn(
'{} not installed or not available in PATH'.format(
self.program
)
Expand Down Expand Up @@ -70,6 +71,12 @@ def list(self):
return json.loads(data.decode('utf-8'))

def _execute(self, subcmd, data_input):
if self.exe is None:
raise errors.StoreError(
'{} not installed or not available in PATH'.format(
self.program
)
)
output = None
env = create_environment_dict(self.environment)
try:
Expand Down
7 changes: 7 additions & 0 deletions tests/integration/credentials/store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,10 @@ def test_execute_with_env_override(self):
data = self.store._execute('--null', '')
assert b'\0FOO=bar\0' in data
assert 'FOO' not in os.environ

def test_unavailable_store(self):
some_unavailable_store = None
with pytest.warns(UserWarning):
some_unavailable_store = Store('that-does-not-exist')
with pytest.raises(StoreError):
some_unavailable_store.get('anything-this-does-not-matter')