Skip to content

Commit 556f711

Browse files
committed
Merge branch 'refactor-abnormal-exit' into 'master'
Generalize abnormal exit See merge request mkjeldsen/commitmsgfmt!66
2 parents 421e2cb + 3536492 commit 556f711

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/main.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ Some text is exempt from wrapping:
155155

156156
let cfg = Config::new(&m);
157157
if let Err(ref e) = cfg {
158-
fatal(e);
158+
exit_abnormally(e);
159159
}
160160
let cfg = cfg.unwrap();
161161

@@ -166,16 +166,8 @@ Some text is exempt from wrapping:
166166
.map(|text| commitmsgfmt.filter(&text))
167167
.and_then(to_stdout);
168168

169-
match result {
170-
Ok(()) => (),
171-
Err(ref err) => match *err {
172-
CliError::Io(ref e) if e.kind() == io::ErrorKind::BrokenPipe => {
173-
std::process::exit(141 /* 128 + 13 */);
174-
}
175-
_ => {
176-
fatal(err);
177-
}
178-
},
169+
if let Err(ref e) = result {
170+
exit_abnormally(e);
179171
}
180172
}
181173

@@ -207,9 +199,19 @@ fn to_stdout<'a>(msg: String) -> CliResult<'a, ()> {
207199
Ok(())
208200
}
209201

210-
fn fatal(e: &CliError) {
211-
eprintln!("fatal: {}", e);
212-
::std::process::exit(1);
202+
fn exit_abnormally(e: &CliError) {
203+
let ret = match e {
204+
CliError::Io(ref e) if e.kind() == io::ErrorKind::BrokenPipe => {
205+
let ret = 128 + 13;
206+
debug_assert!(ret == 141);
207+
ret
208+
}
209+
_ => {
210+
eprintln!("fatal: {}", e);
211+
1
212+
}
213+
};
214+
::std::process::exit(ret);
213215
}
214216

215217
#[cfg(test)]

0 commit comments

Comments
 (0)