Skip to content

Commit 22718ba

Browse files
authored
fix(store): warn on init instead of throw (#3080)
Signed-off-by: yanlong.wang <yanlong.wang@naiver.org>
1 parent d38b41a commit 22718ba

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

docker/credentials/store.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import shutil
44
import subprocess
5+
import warnings
56

67
from . import constants
78
from . import errors
@@ -18,7 +19,7 @@ def __init__(self, program, environment=None):
1819
self.exe = shutil.which(self.program)
1920
self.environment = environment
2021
if self.exe is None:
21-
raise errors.InitializationError(
22+
warnings.warn(
2223
'{} not installed or not available in PATH'.format(
2324
self.program
2425
)
@@ -70,6 +71,12 @@ def list(self):
7071
return json.loads(data.decode('utf-8'))
7172

7273
def _execute(self, subcmd, data_input):
74+
if self.exe is None:
75+
raise errors.StoreError(
76+
'{} not installed or not available in PATH'.format(
77+
self.program
78+
)
79+
)
7380
output = None
7481
env = create_environment_dict(self.environment)
7582
try:

tests/integration/credentials/store_test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,10 @@ def test_execute_with_env_override(self):
8484
data = self.store._execute('--null', '')
8585
assert b'\0FOO=bar\0' in data
8686
assert 'FOO' not in os.environ
87+
88+
def test_unavailable_store(self):
89+
some_unavailable_store = None
90+
with pytest.warns(UserWarning):
91+
some_unavailable_store = Store('that-does-not-exist')
92+
with pytest.raises(StoreError):
93+
some_unavailable_store.get('anything-this-does-not-matter')

0 commit comments

Comments
 (0)