added custom result type
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing

This commit is contained in:
Jake Hillion 2022-04-08 10:53:31 +01:00
parent 23f5761d05
commit f2c9dddb67
5 changed files with 13 additions and 11 deletions

View File

@ -2,6 +2,8 @@ use std::io;
use thiserror::Error;
pub type Result<T> = std::result::Result<T, Error>;
#[derive(Error, Debug)]
pub enum Error {
#[error("{msg}: {src}")]

View File

@ -6,7 +6,7 @@ mod spawner;
mod specification;
mod void;
use error::Error;
use error::{Error, Result};
use spawner::Spawner;
use specification::Specification;
@ -18,7 +18,7 @@ use clap::{App, AppSettings};
use nix::fcntl::OFlag;
use nix::unistd::{self};
pub fn run() -> Result<(), Error> {
pub fn run() -> Result<()> {
// process arguments
let matches = App::new("clone-shim")
.version(env!("GIT_HASH"))
@ -98,7 +98,7 @@ impl PipePair {
}
}
fn create_pipes(names: Vec<&str>) -> Result<HashMap<String, PipePair>, Error> {
fn create_pipes(names: Vec<&str>) -> Result<HashMap<String, PipePair>> {
let mut pipes = HashMap::new();
for pipe in names {

View File

@ -3,7 +3,7 @@ use log::{debug, error, info};
use super::specification::{Arg, Entrypoint, Pipe, Specification, Trigger};
use super::PipePair;
use crate::void::VoidBuilder;
use crate::Error;
use crate::{Error, Result};
use std::collections::HashMap;
use std::ffi::CString;
@ -24,7 +24,7 @@ pub struct Spawner<'a> {
}
impl<'a> Spawner<'a> {
pub fn spawn(&mut self) -> Result<(), Error> {
pub fn spawn(&mut self) -> Result<()> {
for (name, entrypoint) in &self.spec.entrypoints {
info!("spawning entrypoint `{}`", name.as_str());
@ -79,7 +79,7 @@ impl<'a> Spawner<'a> {
Ok(())
}
fn pipe_trigger(&self, mut pipe: File, spec: &Entrypoint, name: &str) -> Result<(), Error> {
fn pipe_trigger(&self, mut pipe: File, spec: &Entrypoint, name: &str) -> Result<()> {
let mut buf = [0_u8; BUFFER_SIZE];
loop {

View File

@ -1,6 +1,6 @@
use log::debug;
use crate::Error;
use crate::{Error, Result};
use std::collections::{HashMap, HashSet};
use std::path::PathBuf;
@ -115,7 +115,7 @@ impl Specification {
(read, write)
}
pub fn validate(&self) -> Result<(), Error> {
pub fn validate(&self) -> Result<()> {
// validate pipes match
let (read, write) = self.pipes();
let mut read_set = HashSet::with_capacity(read.len());

View File

@ -1,5 +1,5 @@
use crate::clone::{clone3, CloneArgs, CloneFlags};
use crate::Error;
use crate::{Error, Result};
use std::collections::HashMap;
use std::fs;
@ -29,7 +29,7 @@ impl VoidBuilder {
self
}
pub fn spawn(&mut self, child_fn: impl FnOnce() -> i32) -> Result<VoidHandle, Error> {
pub fn spawn(&mut self, child_fn: impl FnOnce() -> i32) -> Result<VoidHandle> {
let mut args = CloneArgs::new(
CloneFlags::CLONE_NEWCGROUP
| CloneFlags::CLONE_NEWIPC
@ -63,7 +63,7 @@ impl VoidBuilder {
}
// per-namespace void creation
fn newns_post(&self) -> Result<(), Error> {
fn newns_post(&self) -> Result<()> {
// consume the TempDir so it doesn't get deleted
let new_root = tempfile::tempdir()?.into_path();