{"record":{"id":"b1c2efb3f01576a8","repo":"docker/cli","slug":"error-reading-from-s-data-is-empty","errorCode":null,"errorMessage":"error reading from %s: data is empty","messagePattern":"error reading from (.+?): data is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/command/config/create.go","lineNumber":141,"sourceCode":"\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 {\n\t\t\treturn nil, fmt.Errorf(\"error reading from %s: data is empty\", fileName)\n\t\t}\n\t\treturn data, nil\n\t}\n}\n","sourceCodeStart":123,"sourceCodeEnd":146,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/command/config/create.go#L123-L146","documentation":"Returned by readConfigData() when the named config file is opened and read successfully but contains zero bytes (cli/command/config/create.go:140-142). A Swarm config must carry data, so an empty payload is rejected. This mirrors the stdin empty-data check at line 118 but is specific to the file path branch.","triggerScenarios":"Running `docker config create NAME <file>` where <file> exists, is readable, but is 0 bytes long. The read succeeds (yielding len(data)==0) and triggers this explicit guard.","commonSituations":"Truncated/empty file from a failed upstream process, creating a config from a placeholder/template that was never filled, or pointing at /dev/null by mistake.","solutions":["Confirm the file has content: test -s <file> (succeeds only if non-empty).","Regenerate the file from its source if an upstream step failed.","Provide the intended content or use stdin with real data."],"exampleFix":"# before\ndocker config create mycfg /tmp/empty.txt   # 0 bytes\n# after\nprintf 'key=value' > /tmp/config.txt\ndocker config create mycfg /tmp/config.txt","handlingStrategy":"validation","validationCode":"func validateConfigNonEmpty(path string) error {\n    fi, err := os.Stat(path)\n    if err != nil { return err }\n    if fi.Size() == 0 { return fmt.Errorf(\"%s is empty\", path) }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use test -s <path> in shell wrappers to reject empty files before the CLI does.","Regenerate placeholder templates that were never filled."],"tags":["config","swarm","validation","filesystem"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}