From 1a062ddf1e0344e12153d1c549e5d2786757c004 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Wed, 17 Aug 2016 16:40:24 +0200 Subject: [PATCH] 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 Upstream-commit: 8d5a615045f691536baf8a4cb69e0c505bc1cad2 Component: engine --- components/engine/volume/local/local.go | 3 +++ components/engine/volume/local/local_test.go | 1 + 2 files changed, 4 insertions(+) diff --git a/components/engine/volume/local/local.go b/components/engine/volume/local/local.go index 30aa9de4b7..6b1c4f76e6 100644 --- a/components/engine/volume/local/local.go +++ b/components/engine/volume/local/local.go @@ -256,6 +256,9 @@ func (r *Root) Scope() string { } func (r *Root) validateName(name string) error { + if len(name) == 1 { + return validationError{fmt.Errorf("volume name is too short, names should be at least two alphanumeric characters")} + } if !volumeNameRegex.MatchString(name) { return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed", name, utils.RestrictedNameChars)} } diff --git a/components/engine/volume/local/local_test.go b/components/engine/volume/local/local_test.go index 6b9ce55db9..fd1af411d5 100644 --- a/components/engine/volume/local/local_test.go +++ b/components/engine/volume/local/local_test.go @@ -138,6 +138,7 @@ func TestCreate(t *testing.T) { func TestValidateName(t *testing.T) { r := &Root{} names := map[string]bool{ + "x": false, "/testvol": false, "thing.d": true, "hello-world": true,