Browse code

improve error message for volume names that are too short

this improves the error message if a user tries to
create a volume with a single-character name:

Before this change:

docker volume create --name a
Error response from daemon: create a: "a" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed

After this change:

docker volume create --name a
Error response from daemon: create a: volume name is too short, names should be at least two alphanumeric characters

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>

Sebastiaan van Stijn authored on 2016/08/17 23:40:24
Showing 2 changed files
... ...
@@ -256,6 +256,9 @@ func (r *Root) Scope() string {
256 256
 }
257 257
 
258 258
 func (r *Root) validateName(name string) error {
259
+	if len(name) == 1 {
260
+		return validationError{fmt.Errorf("volume name is too short, names should be at least two alphanumeric characters")}
261
+	}
259 262
 	if !volumeNameRegex.MatchString(name) {
260 263
 		return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed", name, utils.RestrictedNameChars)}
261 264
 	}
... ...
@@ -138,6 +138,7 @@ func TestCreate(t *testing.T) {
138 138
 func TestValidateName(t *testing.T) {
139 139
 	r := &Root{}
140 140
 	names := map[string]bool{
141
+		"x":           false,
141 142
 		"/testvol":    false,
142 143
 		"thing.d":     true,
143 144
 		"hello-world": true,