iced_test/
error.rs

1use crate::Instruction;
2use crate::ice;
3
4use std::io;
5use std::path::PathBuf;
6use std::sync::Arc;
7
8/// A test error.
9#[derive(Debug, Clone, thiserror::Error)]
10pub enum Error {
11    /// No matching widget was found for the [`Selector`](crate::Selector).
12    #[error("no matching widget was found for the selector: {selector}")]
13    SelectorNotFound {
14        /// A description of the selector.
15        selector: String,
16    },
17    /// A target matched, but is not visible.
18    #[error("the matching target is not visible: {target:?}")]
19    TargetNotVisible {
20        /// The target
21        target: Arc<dyn std::fmt::Debug + Send + Sync>,
22    },
23    /// An IO operation failed.
24    #[error("an IO operation failed: {0}")]
25    IOFailed(Arc<io::Error>),
26    /// The decoding of some PNG image failed.
27    #[error("the decoding of some PNG image failed: {0}")]
28    PngDecodingFailed(Arc<png::DecodingError>),
29    /// The encoding of some PNG image failed.
30    #[error("the encoding of some PNG image failed: {0}")]
31    PngEncodingFailed(Arc<png::EncodingError>),
32    /// The parsing of an [`Ice`](crate::Ice) test failed.
33    #[error("the ice test ({file}) is invalid: {error}")]
34    IceParsingFailed {
35        /// The path of the test.
36        file: PathBuf,
37        /// The parse error.
38        error: ice::ParseError,
39    },
40    /// The execution of an [`Ice`](crate::Ice) test failed.
41    #[error("the ice test ({file}) failed")]
42    IceTestingFailed {
43        /// The path of the test.
44        file: PathBuf,
45        /// The [`Instruction`] that failed.
46        instruction: Instruction,
47    },
48    /// The [`Preset`](crate::program::Preset) of a program could not be found.
49    #[error(
50        "the preset \"{name}\" does not exist (available presets: {available:?})"
51    )]
52    PresetNotFound {
53        /// The name of the [`Preset`](crate::program::Preset).
54        name: String,
55        /// The available set of presets.
56        available: Vec<String>,
57    },
58}
59
60impl From<io::Error> for Error {
61    fn from(error: io::Error) -> Self {
62        Self::IOFailed(Arc::new(error))
63    }
64}
65
66impl From<png::DecodingError> for Error {
67    fn from(error: png::DecodingError) -> Self {
68        Self::PngDecodingFailed(Arc::new(error))
69    }
70}
71
72impl From<png::EncodingError> for Error {
73    fn from(error: png::EncodingError) -> Self {
74        Self::PngEncodingFailed(Arc::new(error))
75    }
76}