From cafe68a92d366942d6bd9579405ec1bc1881def3 Mon Sep 17 00:00:00 2001 From: Aanand Prasad Date: Fri, 2 May 2014 15:07:20 +0100 Subject: [PATCH] Better error message when service names are invalid --- fig/service.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fig/service.py b/fig/service.py index 2fc7125d0..fd141c7d9 100644 --- a/fig/service.py +++ b/fig/service.py @@ -21,6 +21,8 @@ DOCKER_CONFIG_HINTS = { 'volume' : 'volumes', } +VALID_NAME_CHARS = '[a-zA-Z0-9]' + class BuildError(Exception): def __init__(self, service, reason): @@ -38,10 +40,10 @@ class ConfigError(ValueError): class Service(object): def __init__(self, name, client=None, project='default', links=[], **options): - if not re.match('^[a-zA-Z0-9]+$', name): - raise ConfigError('Invalid name: %s' % name) - if not re.match('^[a-zA-Z0-9]+$', project): - raise ConfigError('Invalid project: %s' % project) + if not re.match('^%s+$' % VALID_NAME_CHARS, name): + raise ConfigError('Invalid service name "%s" - only %s are allowed' % (name, VALID_NAME_CHARS)) + if not re.match('^%s+$' % VALID_NAME_CHARS, project): + raise ConfigError('Invalid project name "%s" - only %s are allowed' % (project, VALID_NAME_CHARS)) if 'image' in options and 'build' in options: raise ConfigError('Service %s has both an image and build path specified. A service can either be built to image or use an existing image, not both.' % name)