{"record":{"id":"f523fee9d0f70083","repo":"chenhg5/cc-connect","slug":"reading-stdin-w","errorCode":null,"errorMessage":"reading stdin: %w","messagePattern":"reading stdin: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/send.go","lineNumber":168,"sourceCode":"\t\tcase \"--at-all\":\n\t\t\treq.AtAll = true\n\t\tcase \"--data-dir\":\n\t\t\tif i+1 >= len(args) {\n\t\t\t\treturn req, \"\", fmt.Errorf(\"--data-dir requires a value\")\n\t\t\t}\n\t\t\ti++\n\t\t\tdataDir = args[i]\n\t\tcase \"--help\", \"-h\":\n\t\t\treturn req, \"\", errSendUsage\n\t\tdefault:\n\t\t\tpositional = append(positional, args[i])\n\t\t}\n\t}\n\n\tif useStdin {\n\t\tdata, err := io.ReadAll(os.Stdin)\n\t\tif err != nil {\n\t\t\treturn req, \"\", fmt.Errorf(\"reading stdin: %w\", err)\n\t\t}\n\t\treq.Message = strings.TrimSpace(string(data))\n\t}\n\tif req.Project == \"\" {\n\t\treq.Project = strings.TrimSpace(os.Getenv(\"CC_PROJECT\"))\n\t}\n\tif req.SessionKey == \"\" {\n\t\treq.SessionKey = strings.TrimSpace(os.Getenv(\"CC_SESSION_KEY\"))\n\t}\n\tif req.Message == \"\" {\n\t\treq.Message = strings.Join(positional, \" \")\n\t}\n\n\tmaxAtt := resolveMaxAttachmentSize(loadSendConfigBestEffort())\n\n\timages, err := loadImageAttachments(imagePaths, maxAtt)\n\tif err != nil {\n\t\treturn req, \"\", err","sourceCodeStart":150,"sourceCodeEnd":186,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/send.go#L150-L186","documentation":"When `cc-connect send --stdin` is used, parseSendArgs reads the whole of os.Stdin with io.ReadAll and wraps any read failure as \"reading stdin: %w\". This indicates the OS-level read of the standard input stream failed, not an empty or malformed message.","triggerScenarios":"`cc-connect send --stdin` where stdin is a closed/invalid descriptor, a pipe whose writer exited with an I/O error, or stdin redirected from an unreadable file.","commonSituations":"CI job where the upstream pipe was closed early; running under a supervisor that detached fds; piping from a command that itself failed; redirecting stdin from a directory or special file.","solutions":["Ensure the producer actually writes and closes successfully: `echo \"msg\" | cc-connect send --stdin`.","Check the upstream command's exit status; fix its own I/O error first.","Avoid redirecting stdin from a directory or other non-readable file; use `< /dev/null` only when not passing --stdin.","Pass the message as an argument instead of --stdin if stdin is unreliable in your environment."],"exampleFix":"// before\nsome_flaky_cmd | cc-connect send --stdin\n// after\nmsg=$(some_cmd) && printf '%s' \"$msg\" | cc-connect send --stdin","handlingStrategy":"try-catch","validationCode":"# check upstream succeeds before piping\nset -o pipefail\nproducer_cmd | cc-connect send --stdin","typeGuard":null,"tryCatchPattern":"out, err := cmd.CombinedOutput()\nif err != nil && strings.Contains(string(out), \"reading stdin:\") {\n    log.Printf(\"stdin read failed, check producer: %v\", err)\n}","preventionTips":["Use set -o pipefail to surface upstream pipe errors.","Redirect from /dev/null explicitly when there is no input (and don't pass --stdin).","Avoid piping from directories or special files.","Prefer --message when stdin is unreliable in your environment."],"tags":["io","stdin","cli"],"backgroundTag":"file-read-failed","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}