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("the preset \"{name}\" does not exist (available presets: {available:?})")]
50    PresetNotFound {
51        /// The name of the [`Preset`](crate::program::Preset).
52        name: String,
53        /// The available set of presets.
54        available: Vec<String>,
55    },
56}
57
58impl From<io::Error> for Error {
59    fn from(error: io::Error) -> Self {
60        Self::IOFailed(Arc::new(error))
61    }
62}
63
64impl From<png::DecodingError> for Error {
65    fn from(error: png::DecodingError) -> Self {
66        Self::PngDecodingFailed(Arc::new(error))
67    }
68}
69
70impl From<png::EncodingError> for Error {
71    fn from(error: png::EncodingError) -> Self {
72        Self::PngEncodingFailed(Arc::new(error))
73    }
74}