Skip to content
This repository has been archived by the owner on Oct 13, 2023. It is now read-only.

Commit

Permalink
improve error message for volume names that are too short
Browse files Browse the repository at this point in the history
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>
Upstream-commit: 8d5a615
Component: engine
  • Loading branch information
thaJeztah committed Aug 17, 2016
1 parent a410528 commit 1a062dd
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
3 changes: 3 additions & 0 deletions components/engine/volume/local/local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)}
}
Expand Down
1 change: 1 addition & 0 deletions components/engine/volume/local/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 1a062dd

Please sign in to comment.