Skip to content

Commit 26ff248

Browse files
committed
Raise InvalidArgument exception when invalid arguments are provided
Signed-off-by: Joffrey F <[email protected]>
1 parent ab77032 commit 26ff248

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

docker/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ class InvalidConfigFile(DockerException):
9393
pass
9494

9595

96+
class InvalidArgument(DockerException):
97+
pass
98+
99+
96100
class DeprecatedMethod(DockerException):
97101
pass
98102

docker/types/services.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def __init__(self, target, source, type='volume', read_only=False,
131131
self['Target'] = target
132132
self['Source'] = source
133133
if type not in ('bind', 'volume'):
134-
raise errors.DockerError(
134+
raise errors.InvalidArgument(
135135
'Only acceptable mount types are `bind` and `volume`.'
136136
)
137137
self['Type'] = type
@@ -143,7 +143,7 @@ def __init__(self, target, source, type='volume', read_only=False,
143143
'Propagation': propagation
144144
}
145145
if any([labels, driver_config, no_copy]):
146-
raise errors.DockerError(
146+
raise errors.InvalidArgument(
147147
'Mount type is binding but volume options have been '
148148
'provided.'
149149
)
@@ -158,7 +158,7 @@ def __init__(self, target, source, type='volume', read_only=False,
158158
if volume_opts:
159159
self['VolumeOptions'] = volume_opts
160160
if propagation:
161-
raise errors.DockerError(
161+
raise errors.InvalidArgument(
162162
'Mount type is volume but `propagation` argument has been '
163163
'provided.'
164164
)
@@ -167,11 +167,11 @@ def __init__(self, target, source, type='volume', read_only=False,
167167
def parse_mount_string(cls, string):
168168
parts = string.split(':')
169169
if len(parts) > 3:
170-
raise errors.DockerError(
170+
raise errors.InvalidArgument(
171171
'Invalid mount format "{0}"'.format(string)
172172
)
173173
if len(parts) == 1:
174-
return cls(target=parts[0])
174+
return cls(target=parts[0], source=None)
175175
else:
176176
target = parts[1]
177177
source = parts[0]
@@ -229,7 +229,7 @@ def __init__(self, parallelism=0, delay=None, failure_action='continue'):
229229
if delay is not None:
230230
self['Delay'] = delay
231231
if failure_action not in ('pause', 'continue'):
232-
raise errors.DockerError(
232+
raise errors.InvalidArgument(
233233
'failure_action must be either `pause` or `continue`.'
234234
)
235235
self['FailureAction'] = failure_action

0 commit comments

Comments
 (0)