{"record":{"id":"235257a8fe099851","repo":"amir20/dozzle","slug":"failed-to-write-to-stdout-w","errorCode":null,"errorMessage":"failed to write to stdout: %w","messagePattern":"failed to write to stdout: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/support/cli/generate_command.go","lineNumber":54,"sourceCode":"\t\tif password, err = readPassword(); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\tif password == \"\" {\n\t\treturn fmt.Errorf(\"password is required\")\n\t}\n\n\tbuffer := auth.GenerateUsers(auth.User{\n\t\tUsername:        args.Generate.Username,\n\t\tPassword:        password,\n\t\tName:            args.Generate.Name,\n\t\tEmail:           args.Generate.Email,\n\t\tFilter:          args.Generate.Filter,\n\t\tRolesConfigured: args.Generate.RolesConfigured,\n\t}, true)\n\n\tif _, err := os.Stdout.Write(buffer.Bytes()); err != nil {\n\t\treturn fmt.Errorf(\"failed to write to stdout: %w\", err)\n\t}\n\n\treturn nil\n}\n\n// readPassword reads a password from stdin. Prompts are written to stderr so\n// they don't pollute stdout (which is commonly redirected to users.yml). When\n// stdin is a terminal the input is read without echo; otherwise a single line\n// is read (supports piping, e.g. `echo secret | dozzle generate ...`).\nfunc readPassword() (string, error) {\n\tfd := int(os.Stdin.Fd())\n\tif term.IsTerminal(fd) {\n\t\tfmt.Fprint(os.Stderr, \"Password: \")\n\t\tbytePassword, err := term.ReadPassword(fd)\n\t\tfmt.Fprintln(os.Stderr)\n\t\tif err != nil {\n\t\t\treturn \"\", fmt.Errorf(\"failed to read password: %w\", err)\n\t\t}","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/amir20/dozzle/blob/d9463cbe21874e44ab79db6fa63e746ca7d22928/internal/support/cli/generate_command.go#L36-L72","documentation":"After generating the users.yml content into an in-memory buffer, `dozzle generate` writes it to stdout. If that write fails (broken pipe, closed stdout), the underlying error is wrapped with this message.","triggerScenarios":"Running `dozzle generate` with stdout closed or redirected to a broken destination, e.g. `dozzle generate | head -0` or piping into a process that has already exited (EPIPE).","commonSituations":"Piping output into `head`/`grep` that exits early; redirecting stdout to a full disk or closed file descriptor in shell scripts.","solutions":["Pipe into a command that consumes the full output, or redirect to a file: `dozzle generate > users.yml`","Check disk space / file descriptor validity when redirecting stdout","Avoid piping into commands that close stdin early"],"exampleFix":"// before\ndozzle generate | head -1\n// after\ndozzle generate > users.yml","handlingStrategy":"try-catch","validationCode":"dozzle generate > users.yml || echo \"generate failed\" >&2","typeGuard":null,"tryCatchPattern":"if ! out=$(dozzle generate); then\n  echo \"generate failed: $out\" >&2\n  exit 1\nfi","preventionTips":["Redirect stdout to a file rather than short-lived pipes","Avoid piping into head/grep that may exit before all output is written"],"tags":["cli","io","stdout"],"backgroundTag":"broken-pipe","analyzedSha":"d9463cbe21874e44ab79db6fa63e746ca7d22928","analyzedAt":"2026-09-07T10:08:55.855Z","contentChangedAt":"2026-09-07T10:08:55.855Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}