cargo_tarpaulin/errors/
mod.rs1#![cfg(not(tarpaulin_include))]
2use crate::report::cobertura;
3use std::fmt::{self, Display, Formatter};
4
5#[derive(Debug)]
7pub enum RunError {
8 Manifest(String),
10 Cargo(String),
12 Packages(String),
14 TestLaunch(String),
16 TestCompile(String),
18 TestRuntime(String),
20 TestFailed,
21 Parse(std::io::Error),
23 TestCoverage(String),
25 Trace(String),
26 CovReport(String),
27 OutFormat(String),
28 IO(std::io::Error),
29 StateMachine(String),
30 #[cfg(ptrace_supported)]
31 NixError(nix::Error),
32 Html(String),
33 XML(cobertura::Error),
34 Lcov(String),
35 Json(String),
36 Internal,
37 BelowThreshold(f64, f64),
39 Engine(String),
41}
42
43impl Display for RunError {
44 fn fmt(&self, f: &mut Formatter) -> fmt::Result {
45 match self {
46 Self::Manifest(e) => write!(f, "Failed to parse Cargo.toml! Error: {e}"),
47 Self::Cargo(e) => write!(f, "Cargo failed to run! Error: {e}"),
48 Self::Packages(e) => write!(f, "Failed to resolve package in manifest! Error: {e}"),
49 Self::TestLaunch(e) => write!(f, "Failed to launch test: {e}"),
50 Self::TestCompile(e) => write!(f, "Failed to compile tests!\n{e}"),
51 Self::TestRuntime(e) => write!(f, "Failed to run tests: {e}"),
52 Self::TestFailed => write!(f, "Test failed during run"),
53 Self::Parse(e) => write!(f, "Error while parsing: {e}"),
54 Self::TestCoverage(e) => write!(f, "Failed to get test coverage! Error: {e}"),
55 Self::Trace(e) => write!(f, "Failed to trace! Error: {e}"),
57 Self::CovReport(e) => write!(f, "Failed to report coverage! Error: {e}"),
58 Self::OutFormat(e) => write!(f, "{e}"),
59 Self::IO(e) => write!(f, "{e}"),
60 Self::StateMachine(e) => write!(f, "Error running test: {e}"),
61 #[cfg(ptrace_supported)]
62 Self::NixError(e) => write!(f, "{e}"),
63 Self::Html(e) => write!(f, "Failed to generate HTML report! Error: {e}"),
64 Self::XML(e) => write!(f, "Failed to generate XML report! Error: {e}"),
65 Self::Lcov(e) => write!(f, "Failed to generate Lcov report! Error: {e}"),
66 Self::Json(e) => write!(f, "Failed to generate JSON report! Error: {e}"),
67 Self::Internal => write!(f, "Tarpaulin experienced an internal error"),
68 Self::BelowThreshold(a, e) => {
69 write!(
70 f,
71 "Coverage is below the failure threshold {a:.2}% < {e:.2}%"
72 )
73 }
74 Self::Engine(s) => write!(f, "Engine error: {s}"),
75 }
76 }
77}
78
79impl From<std::io::Error> for RunError {
80 fn from(e: std::io::Error) -> Self {
81 RunError::IO(e)
82 }
83}
84
85#[cfg(ptrace_supported)]
86impl From<nix::Error> for RunError {
87 fn from(e: nix::Error) -> Self {
88 RunError::NixError(e)
89 }
90}
91
92impl From<cobertura::Error> for RunError {
93 fn from(e: cobertura::Error) -> Self {
94 RunError::XML(e)
95 }
96}
97
98impl From<serde_json::error::Error> for RunError {
99 fn from(e: serde_json::error::Error) -> Self {
100 RunError::Json(e.to_string())
101 }
102}