April 26th, 2024 08:06 UTC · 6 months ago

RustPetnamesTesting

An embarrassing bug

An embarrassing bug found its way into yesterday’s release of rust-petname 2.0.0: using petname at the command-line would often result in nothing being printed.

Mistake #1

At some point I had wrapped stdout with a buffered writer. It was never being explicitly flushed, but its Drop impl does that so it should have been good. However, I was creating the buffer in main and keeping it in scope until the end of the function – and since I was calling std::process::exit directly in main, the buffer’s Drop impl was not called before the process exited.

Mistake #2

I didn’t realise it! 🤦‍♂️ This is the embarrassing part. Somehow I had not run petname at the command-line at any point before releasing it. Seems inconceivable, but there it is.

Lesson

Write at least one test that exercises the software from the outside, or at least put it on the pre-release checklist.

Filed as issue #109.

A fix has already been released in 2.0.1 which flushes the writer explicitly and ensures that it is dropped before exiting the process.