From defbe23debbbd8d68ebd474901feb8e700893201 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 30 Jan 2026 14:07:53 +0100 Subject: [PATCH] opts: MountOpt: improve error for empty value Before this patch: docker run --rm --mount "" busybox invalid argument "" for "--mount" flag: EOF With this patch: docker run --rm --mount "" busybox invalid argument "" for "--mount" flag: value is empty Signed-off-by: Sebastiaan van Stijn --- opts/mount.go | 5 +++++ opts/mount_test.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/opts/mount.go b/opts/mount.go index 0ac252f31187..682717f164df 100644 --- a/opts/mount.go +++ b/opts/mount.go @@ -22,6 +22,11 @@ type MountOpt struct { // //nolint:gocyclo func (m *MountOpt) Set(value string) error { + value = strings.TrimSpace(value) + if value == "" { + return errors.New("value is empty") + } + csvReader := csv.NewReader(strings.NewReader(value)) fields, err := csvReader.Read() if err != nil { diff --git a/opts/mount_test.go b/opts/mount_test.go index 05f4c7161714..96d1a7357942 100644 --- a/opts/mount_test.go +++ b/opts/mount_test.go @@ -109,6 +109,10 @@ func TestMountOptErrors(t *testing.T) { tests := []struct { doc, value, expErr string }{ + { + doc: "empty value", + expErr: "value is empty", + }, { doc: "missing tmpfs target", value: "type=tmpfs",