1use std::fmt;
4use std::path::PathBuf;
5use std::process::ExitStatus;
6
7#[derive(Debug)]
9pub enum Error {
10 NoBackend,
13 Spawn {
15 program: PathBuf,
16 source: std::io::Error,
17 },
18 Exit {
20 program: PathBuf,
21 status: ExitStatus,
22 },
23}
24
25impl fmt::Display for Error {
26 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27 match self {
28 Error::NoBackend => {
29 write!(
30 f,
31 "no dialog backend available (none of kdialog, zenity, osascript, or powershell was found)"
32 )
33 }
34 Error::Spawn { program, source } => {
35 write!(f, "could not run {}: {source}", program.display())
36 }
37 Error::Exit { program, status } => {
38 write!(f, "{} exited with {status}", program.display())
39 }
40 }
41 }
42}
43
44impl std::error::Error for Error {
45 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
46 match self {
47 Error::Spawn { source, .. } => Some(source),
48 _ => None,
49 }
50 }
51}