{"record":{"id":"f58167f088516128","repo":"docker/cli","slug":"source-is-required-f58167","errorCode":null,"errorMessage":"source is required","messagePattern":"source is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"opts/swarmopts/secret.go","lineNumber":71,"sourceCode":"\t\t\toptions.File.Name = val\n\t\tcase \"uid\":\n\t\t\toptions.File.UID = val\n\t\tcase \"gid\":\n\t\t\toptions.File.GID = val\n\t\tcase \"mode\":\n\t\t\tm, err := strconv.ParseUint(val, 0, 32)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"invalid mode specified: %v\", err)\n\t\t\t}\n\n\t\t\toptions.File.Mode = os.FileMode(m)\n\t\tdefault:\n\t\t\treturn errors.New(\"invalid field in secret request: \" + key)\n\t\t}\n\t}\n\n\tif options.SecretName == \"\" {\n\t\treturn errors.New(\"source is required\")\n\t}\n\tif options.File.Name == \"\" {\n\t\toptions.File.Name = options.SecretName\n\t}\n\n\to.values = append(o.values, options)\n\treturn nil\n}\n\n// Type returns the type of this option\nfunc (*SecretOpt) Type() string {\n\treturn \"secret\"\n}\n\n// String returns a string repr of this option\nfunc (o *SecretOpt) String() string {\n\tsecrets := make([]string, 0, len(o.values))\n\tfor _, secret := range o.values {","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/opts/swarmopts/secret.go#L53-L89","documentation":"Thrown by SecretOpt.Set when a key=value --secret spec omits the source/src key. A Swarm secret reference requires a source secret name; the parser validates this after all fields are consumed. The short form (--secret foo) auto-sets source and never hits this.","triggerScenarios":"Passing --secret target=/run/secrets/pw,uid=33 without a source=, or any secret spec missing the secret name.","commonSituations":"Assuming target alone names the secret, or a partial spec where the source field was dropped during edits.","solutions":["Add source=<secretname> (or src=) to the --secret spec.","Use the short form --secret <secretname> when no other overrides are needed.","Confirm the secret exists with docker secret ls before referencing it."],"exampleFix":"// before\n--secret target=/run/secrets/pw\n// after\n--secret source=dbpw,target=/run/secrets/pw","handlingStrategy":"validation","validationCode":"hasSource := false\nfor _, f := range strings.Split(spec, \",\") {\n    k, _, _ := strings.Cut(strings.ToLower(f), \"=\")\n    if k == \"source\" || k == \"src\" {\n        hasSource = true\n    }\n}\nif !hasSource && !(len(strings.Split(spec, \",\")) == 1 && !strings.Contains(spec, \"=\")) {\n    return errors.New(\"secret spec requires source=\")\n}","typeGuard":null,"tryCatchPattern":"if err := secretOpt.Set(spec); err != nil {\n    return err\n}","preventionTips":["Always include source= in key=value secret specs.","Prefer the short form --secret <name> for simple cases."],"tags":["swarm","secrets","validation","opts"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}