bt_rs/common/
version_error.rs1use std::{
4 error as std_error,
5 fmt as std_fmt,
6 io as std_io,
7};
8
9
10#[derive(Debug)]
12pub enum VersionError {
13 InvocationFailed(std_io::Error),
15 InvalidUtf8,
17 UnrecognisedOutput,
19 InvalidVersionComponent {
21 component : &'static str,
22 value : String,
23 },
24}
25
26
27impl std_fmt::Display for VersionError {
30 fn fmt(
31 &self,
32 f : &mut std_fmt::Formatter<'_>,
33 ) -> std_fmt::Result {
34 match self {
35 Self::InvocationFailed(e) => {
36 write!(f, "failed to execute tool `--version`: {e}")
37 },
38 Self::InvalidUtf8 => {
39 write!(f, "tool `--version` stdout was not valid UTF-8")
40 },
41 Self::UnrecognisedOutput => {
42 write!(f, "tool `--version` output was not recognised")
43 },
44 Self::InvalidVersionComponent { component, value } => {
45 write!(
46 f,
47 "invalid {component} component in tool `--version` output: {value:?}"
48 )
49 },
50 }
51 }
52}
53
54impl std_error::Error for VersionError {
55 fn source(&self) -> Option<&(dyn std_error::Error + 'static)> {
56 match self {
57 Self::InvocationFailed(e) => Some(e),
58 _ => None,
59 }
60 }
61}
62
63
64