rusty_fork/error.rs
1//-
2// Copyright 2018 Jason Lingle
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use std::io;
11
12use crate::cmdline;
13
14quick_error! {
15 /// Enum for errors produced by the rusty-fork crate.
16 #[derive(Debug)]
17 pub enum Error {
18 /// An unknown flag was encountered when examining the current
19 /// process's argument list.
20 ///
21 /// The string is the flag that was encountered.
22 UnknownFlag(flag: String) {
23 display("The flag '{:?}' was passed to the Rust test \
24 process, but rusty-fork does not know how to \
25 handle it.\n\
26 If you are using the standard Rust \
27 test harness and have the latest version of the \
28 rusty-fork crate, please report a bug to\n\
29 \thttps://github.com/AltSysrq/rusty-fork/issues\n\
30 In the mean time, you can tell rusty-fork how to \
31 handle this flag by setting the environment variable \
32 `{}` to one of the following values:\n\
33 \tpass - Pass the flag (alone) to the child process\n\
34 \tpass-arg - Pass the flag and its following argument \
35 to the child process.\n\
36 \tdrop - Don't pass the flag to the child process.\n\
37 \tdrop-arg - Don't pass the flag or its following \
38 argument to the child process.",
39 flag, cmdline::env_var_for_flag(&flag))
40 }
41 /// A flag was encountered when examining the current process's
42 /// argument list which is known but cannot be handled in any sensible
43 /// way.
44 ///
45 /// The strings are the flag encountered and a human-readable message
46 /// about why the flag could not be handled.
47 DisallowedFlag(flag: String, message: String) {
48 display("The flag '{:?}' was passed to the Rust test \
49 process, but rusty-fork cannot handle it; \
50 reason: {}", flag, message)
51 }
52 /// Spawning a subprocess failed.
53 SpawnError(err: io::Error) {
54 from()
55 cause(err)
56 display("Spawn failed: {}", err)
57 }
58 }
59}
60
61/// General `Result` type for rusty-fork.
62pub type Result<T> = ::std::result::Result<T, Error>;