remote_server: Avoid panic when writing to stderr (#47683)

Cole Miller created

Closes ZED-4JM

Release Notes:

- N/A

Change summary

crates/remote_server/src/main.rs | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)

Detailed changes

crates/remote_server/src/main.rs 🔗

@@ -1,5 +1,6 @@
 use clap::Parser;
 use remote_server::Commands;
+use std::io::Write as _;
 use std::path::PathBuf;
 
 #[derive(Parser)]
@@ -45,7 +46,7 @@ fn main() -> anyhow::Result<()> {
         if let Err(e) = &res
             && let Some(e) = e.downcast_ref::<ExecuteProxyError>()
         {
-            eprintln!("{e:#}");
+            std::io::stderr().write_fmt(format_args!("{e:#}\n")).ok();
             // It is important for us to report the proxy spawn exit code here
             // instead of the generic 1 that result returns
             // The client reads the exit code to determine if the server process has died when trying to reconnect
@@ -54,7 +55,9 @@ fn main() -> anyhow::Result<()> {
         }
         res
     } else {
-        eprintln!("usage: remote <run|proxy|version>");
+        std::io::stderr()
+            .write_all(b"usage: remote <run|proxy|version>\n")
+            .ok();
         std::process::exit(1);
     }
 }