Skip to content

Commit 8b6ae57

Browse files
authored
Merge pull request #8 from jjs-dev/thiserrror
Use thiserror
2 parents ff7c555 + 349968f commit 8b6ae57

File tree

5 files changed

+21
-51
lines changed

5 files changed

+21
-51
lines changed

Cargo.lock

Lines changed: 0 additions & 28 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ serde_json = "1.0.51"
1313
tiny-nix-ipc = { git = "https://github.com/myfreeweb/tiny-nix-ipc", features = ["ser_json", "zero_copy"] }
1414
procfs = "0.7.8"
1515
nix = {git = "https://github.com/nix-rust/nix"}
16-
snafu = "0.6.6"
1716
backtrace = "0.3.46"
18-
thiserror = "1.0.15"
17+
thiserror = "1.0.19"
1918

2019
[workspace]
21-
members = ["minion-ffi", ".", "minion-tests", "minion-cli"]
20+
members = ["minion-ffi", ".", "minion-tests", "minion-cli"]

src/lib.rs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ pub struct ChildProcessOptions {
287287
}
288288

289289
mod errors {
290-
use snafu::Snafu;
291-
292290
#[derive(Eq, PartialEq)]
293291
pub enum ErrorKind {
294292
/// This error typically means that isolated process tried to break its sandbox
@@ -297,26 +295,29 @@ mod errors {
297295
System,
298296
}
299297

300-
#[derive(Debug, Snafu)]
301-
#[snafu(visibility(pub))]
298+
#[derive(Debug, thiserror::Error)]
299+
#[non_exhaustive]
302300
pub enum Error {
303-
#[snafu(display("requested operation is not supported by backend"))]
301+
#[error("requested operation is not supported by backend")]
304302
NotSupported,
305-
#[snafu(display("system call failed in undesired fashion (error code {})", code))]
306-
System { code: i32 },
307-
#[snafu(display("io error"))]
308-
Io { source: std::io::Error },
309-
#[snafu(display("sandbox interaction failed"))]
303+
#[error("system call failed in undesired fashion (error code {})", code)]
304+
Syscall { code: i32 },
305+
#[error("io error")]
306+
Io {
307+
#[from]
308+
source: std::io::Error,
309+
},
310+
#[error("sandbox interaction failed")]
310311
Sandbox,
311-
#[snafu(display("unknown error"))]
312+
#[error("unknown error")]
312313
Unknown,
313314
}
314315

315316
impl Error {
316317
pub fn kind(&self) -> ErrorKind {
317318
match self {
318319
Error::NotSupported => ErrorKind::System,
319-
Error::System { .. } => ErrorKind::System,
320+
Error::Syscall { .. } => ErrorKind::System,
320321
Error::Io { .. } => ErrorKind::System,
321322
Error::Sandbox => ErrorKind::Sandbox,
322323
Error::Unknown => ErrorKind::System,
@@ -335,7 +336,7 @@ mod errors {
335336
impl From<nix::Error> for Error {
336337
fn from(err: nix::Error) -> Self {
337338
if let Some(errno) = err.as_errno() {
338-
Error::System { code: errno as i32 }
339+
Error::Syscall { code: errno as i32 }
339340
} else {
340341
Error::Unknown
341342
}

src/linux.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use crate::{
1616
InputSpecificationData, OutputSpecification, OutputSpecificationData, WaitOutcome,
1717
};
1818
use nix::sys::memfd;
19-
use snafu::ResultExt;
2019
use std::{
2120
ffi::CString,
2221
fs,
@@ -115,7 +114,7 @@ fn handle_input_io(spec: InputSpecification) -> crate::Result<(Option<Handle>, H
115114
Ok((None, h))
116115
}
117116
InputSpecificationData::Empty => {
118-
let file = fs::File::create("/dev/null").context(crate::errors::Io)?;
117+
let file = fs::File::create("/dev/null")?;
119118
let file = file.into_raw_fd();
120119
Ok((None, file))
121120
}
@@ -136,7 +135,7 @@ fn handle_output_io(spec: OutputSpecification) -> crate::Result<(Option<Handle>,
136135
Ok((Some(h_read), f))
137136
}
138137
OutputSpecificationData::Ignore => {
139-
let file = fs::File::open("/dev/null").context(crate::errors::Io)?;
138+
let file = fs::File::open("/dev/null")?;
140139
let file = file.into_raw_fd();
141140
let fd = unsafe { libc::dup(file) };
142141
Ok((None, fd))
@@ -151,10 +150,9 @@ fn handle_output_io(spec: OutputSpecification) -> crate::Result<(Option<Handle>,
151150
let mfd = memfd::memfd_create(&memfd_name, flags).unwrap();
152151
if let Some(sz) = sz {
153152
if unsafe { libc::ftruncate(mfd, sz as i64) } == -1 {
154-
crate::errors::System {
153+
return Err(crate::Error::Syscall {
155154
code: get_last_error(),
156-
}
157-
.fail()?
155+
});
158156
}
159157
}
160158
let child_fd = unsafe { libc::dup(mfd) };

src/linux/zygote.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ fn timed_wait(pid: Pid, timeout: Option<time::Duration>) -> crate::Result<Option
344344
if sys_err == libc::EINTR {
345345
continue;
346346
}
347-
crate::errors::System { code: sys_err }.fail()?
347+
return Err(crate::Error::Syscall { code: sys_err });
348348
}
349349
Ok(0) => None,
350350
Ok(1) => {

0 commit comments

Comments
 (0)