{"record":{"id":"f89186fdd6a0f018","repo":"coding-horror/basic-computer-games","slug":"failed-to-flush","errorCode":null,"errorMessage":"failed to flush","messagePattern":"failed to flush","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"22_Change/rust/src/main.rs","lineNumber":129,"sourceCode":" */\nfn welcome() {\n    println!(\"\\t\\t\\t\\tCHANGE\\n\\t      CREATIVE COMPUTING  MORRISTOWN, NEW JERSEY\\n\\n\\n\");\n}\n\n/**\n * get number of money from user input\n */\nfn get_dollar_value_in_cents_from_user(prompt:&str) -> i16 {\n    let mut value:i16;\n    //input loop\n    loop {\n        //data\n        let mut raw_input = String::new();\n\n        //print prompt\n        print!(\"{}\",prompt);\n        //flush std out // allows prompt to be on same line as input\n        stdout().flush().expect(\"failed to flush\");\n\n        //get input\n        io::stdin().read_line(&mut raw_input).expect(\"failed to read input\");\n        //filter out characters that aren't numbers or '.'\n        let mut no_prior_periods = true;\n        raw_input = raw_input.chars().filter(|c| {\n            if c.eq_ignore_ascii_case(&'.') && no_prior_periods {\n                no_prior_periods = false;\n                true\n            } else {\n                c.is_ascii_digit()\n            }\n        }).collect();\n\n        //should only be (at most) 1 .\n        if !raw_input.contains(\".\") { raw_input += \".00\";} //if there are none, add one\n\n        //ensure there are at least 2 trailing digits","sourceCodeStart":111,"sourceCodeEnd":147,"githubUrl":"https://github.com/coding-horror/basic-computer-games/blob/5301155192d91d74d337899cecc59dbda59c4c17/22_Change/rust/src/main.rs#L111-L147","documentation":"A panic via .expect(\"failed to flush\") on stdout().flush() in get_dollar_value_in_cents_from_user() of the Change (making change) Rust port. The prompt is printed without a trailing newline and flushed so it sits on the same line as the typed input; if stdout cannot be flushed (closed/broken pipe, unwritable redirect), the process panics before reading input.","triggerScenarios":"stdout closed or piped to a consumer that exited (broken pipe/SIGPIPE); redirecting output to a full or read-only file; a parent process closing stdout.","commonSituations":"Piping output through `head`/`tail` that closes the pipe early; redirecting to a full filesystem; a supervisor that closes stdout.","solutions":["Run interactively or redirect to a writable file with adequate space instead of piping through an early-closing consumer.","Replace .expect with `let _ = stdout().flush();` to tolerate flush failure.","Ensure the downstream reader consumes all output."],"exampleFix":"// before\nstdout().flush().expect(\"failed to flush\");\n\n// after\nlet _ = stdout().flush();","handlingStrategy":"fallback","validationCode":"// Avoid piping through early-closing consumers; otherwise discard the flush result.","typeGuard":null,"tryCatchPattern":"// Discard flush result to tolerate broken pipe\nlet _ = stdout().flush();","preventionTips":["Don't pipe stdout through head/tail that close the pipe early.","Use `let _ = stdout().flush()` for prompt flushes.","Handle BrokenPipe explicitly when redirecting output."],"tags":["rust","stdout","io","panic","expect","flush"],"backgroundTag":null,"analyzedSha":"5301155192d91d74d337899cecc59dbda59c4c17","analyzedAt":"2026-08-13T19:29:00.979Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}