remote_server: Avoid panic when writing to stderr (#47683) (cherry-pick to preview) (#47685)

zed-zippy[bot] and Cole Miller created

Cherry-pick of #47683 to preview

----
Closes ZED-4JM

Release Notes:

- N/A

---------

Co-authored-by: Cole Miller <cole@zed.dev>

Change summary

crates/remote_server/src/main.rs | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 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)]
@@ -46,7 +47,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
@@ -55,16 +56,22 @@ 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);
     }
 
     #[cfg(windows)]
     if let Some(_) = cli.command {
-        eprintln!("run is not supported on Windows");
+        std::io::stderr()
+            .write_all(b"run is not supported on Windows\n")
+            .ok();
         std::process::exit(2);
     } else {
-        eprintln!("usage: remote <run|proxy|version>");
+        std::io::stderr()
+            .write_all(b"usage: remote <run|proxy|version>\n")
+            .ok();
         std::process::exit(1);
     }
 }