Patchwork [5,of,8] rust-hglib: abstract away from ExitStatus

login
register
mail settings
Submitter Yuya Nishihara
Date April 1, 2018, 11:14 a.m.
Message ID <6edafeebb3c1440a23bb.1522581261@mimosa>
Download mbox | patch
Permalink /patch/30120/
State Accepted
Headers show

Comments

Yuya Nishihara - April 1, 2018, 11:14 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1522484358 -32400
#      Sat Mar 31 17:19:18 2018 +0900
# Node ID 6edafeebb3c1440a23bb84f24efa0ff24161890d
# Parent  a3c01fe6cf0a036859f76d8c222c4ca9aa32116c
rust-hglib: abstract away from ExitStatus

Prepares for adding a connector for UNIX domain server.

Patch

diff --git a/rust/hglib/src/connection.rs b/rust/hglib/src/connection.rs
--- a/rust/hglib/src/connection.rs
+++ b/rust/hglib/src/connection.rs
@@ -22,7 +22,7 @@  use std::error::Error;
 use std::fmt::{self, Display};
 use std::io;
 use std::io::prelude::*;
-use std::process::{Command, Stdio, Child, ChildStdin, ChildStdout, ExitStatus};
+use std::process::{Command, Stdio, Child, ChildStdin, ChildStdout};
 use std::str;
 
 use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt};
@@ -151,10 +151,17 @@  impl PipeBackend {
         self.child.stdin.as_mut().unwrap()
     }
 
-    fn close(&mut self) -> io::Result<ExitStatus> {
+    fn close(&mut self) -> io::Result<()> {
         // This will close the command server's stdin, which signals
-        // that it should exit. Returns the command server's exit code.
-        self.child.wait()
+        // that it should exit.
+        let st = try!(self.child.wait());
+        if st.success() {
+            Ok(())
+        } else {
+            // TODO: add dedicated error type?
+            return Err(io::Error::new(io::ErrorKind::Other,
+                                      format!("server exited with error: {}", st)))
+        }
     }
 }
 
@@ -278,7 +285,7 @@  impl Connection {
     }
 
     /// Shuts down the command server process.
-    pub fn close(&mut self) -> io::Result<ExitStatus> {
+    pub fn close(&mut self) -> io::Result<()> {
         self.backend.close()
     }
 }