{"record":{"id":"71d83c08acebe1a7","repo":"docker/cli","slug":"config-file-is-required","errorCode":null,"errorMessage":"config file is required","messagePattern":"config file is required","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/config/create.go","lineNumber":122,"sourceCode":"\n// readConfigData reads the config from either stdin or the given fileName.\n//\n// It reads up to twice the maximum size of the config ([maxConfigSize]),\n// just in case swarm's limit changes; this is only a safeguard to prevent\n// reading arbitrary files into memory.\nfunc readConfigData(in io.Reader, fileName string) ([]byte, error) {\n\tswitch fileName {\n\tcase \"-\":\n\t\tdata, err := io.ReadAll(io.LimitReader(in, 2*maxConfigSize))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading from STDIN: %w\", err)\n\t\t}\n\t\tif len(data) == 0 {\n\t\t\treturn nil, errors.New(\"error reading from STDIN: data is empty\")\n\t\t}\n\t\treturn data, nil\n\tcase \"\":\n\t\treturn nil, errors.New(\"config file is required\")\n\tdefault:\n\t\t// Open file with [FILE_FLAG_SEQUENTIAL_SCAN] on Windows, which\n\t\t// prevents Windows from aggressively caching it. We expect this\n\t\t// file to be only read once. Given that this is expected to be\n\t\t// a small file, this may not be a significant optimization, so\n\t\t// we could choose to omit this, and use a regular [os.Open].\n\t\t//\n\t\t// [FILE_FLAG_SEQUENTIAL_SCAN]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea#FILE_FLAG_SEQUENTIAL_SCAN\n\t\tf, err := sequential.Open(fileName)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading from %s: %w\", fileName, err)\n\t\t}\n\t\tdefer f.Close()\n\t\tdata, err := io.ReadAll(io.LimitReader(f, 2*maxConfigSize))\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error reading from %s: %w\", fileName, err)\n\t\t}\n\t\tif len(data) == 0 {","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/config/create.go#L104-L140","documentation":"readConfigData returns errors.New(\"config file is required\") at line 122 when the fileName argument is the empty string. In normal CLI usage this is guarded by Args: cli.ExactArgs(2) on the create command, so this fires primarily for programmatic callers of runCreate/readConfigData who pass an empty file path, or if argument validation is bypassed.","triggerScenarios":"Calling runCreate with createOptions.file == \"\" directly; or invoking the create command in a way that skips the ExactArgs(2) check (custom command wiring, tests). The standard `docker config create NAME` (one arg) would be caught earlier by the Args validator.","commonSituations":"Programmatic use of the config create logic; test fixtures that omit the file; refactors that drop the second positional argument.","solutions":["Always pass a non-empty file path or '-' as the second argument: `docker config create NAME path/or/-`.","In code, validate options.file != \"\" before calling runCreate/readConfigData.","Keep the command's Args: cli.ExactArgs(2) intact so the CLI rejects missing args before reaching this code."],"exampleFix":"// before\nerr := runCreate(ctx, cli, createOptions{name: \"cfg\", file: \"\"})\n// after\nerr := runCreate(ctx, cli, createOptions{name: \"cfg\", file: \"./config.txt\"})","handlingStrategy":"validation","validationCode":"// Programmatic callers: assert a non-empty file before calling runCreate:\nif options.file == \"\" {\n    return errors.New(\"config file is required\")\n}","typeGuard":null,"tryCatchPattern":"if err := runCreate(ctx, cli, opts); err != nil {\n    if strings.Contains(err.Error(), \"config file is required\") {\n        // prompt user for the file path\n    }\n    return err\n}","preventionTips":["Keep Args: cli.ExactArgs(2) on the command so the CLI rejects missing args.","In code, never pass file == \"\"; default to \"-\" or a path.","Validate options struct before invoking runCreate."],"tags":["config","swarm","validation","api-usage"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}