2025-08-27 06:02:02 +02:00
|
|
|
use crate::Instruction;
|
|
|
|
|
use crate::ice;
|
|
|
|
|
|
2025-05-29 16:34:44 +02:00
|
|
|
use std::io;
|
2025-08-27 06:02:02 +02:00
|
|
|
use std::path::PathBuf;
|
2025-05-29 16:34:44 +02:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
|
|
|
|
|
/// A test error.
|
|
|
|
|
#[derive(Debug, Clone, thiserror::Error)]
|
|
|
|
|
pub enum Error {
|
2025-08-23 02:41:52 +02:00
|
|
|
/// No matching widget was found for the [`Selector`](crate::Selector).
|
2025-08-23 01:44:17 +02:00
|
|
|
#[error("no matching widget was found for the selector: {selector}")]
|
2025-09-12 22:53:28 +02:00
|
|
|
SelectorNotFound {
|
|
|
|
|
/// A description of the selector.
|
|
|
|
|
selector: String,
|
|
|
|
|
},
|
|
|
|
|
/// A target matched, but is not visible.
|
2025-08-23 01:44:17 +02:00
|
|
|
#[error("the matching target is not visible: {target:?}")]
|
2025-08-27 06:18:23 +02:00
|
|
|
TargetNotVisible {
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The target
|
2025-08-23 01:44:17 +02:00
|
|
|
target: Arc<dyn std::fmt::Debug + Send + Sync>,
|
|
|
|
|
},
|
2025-05-29 16:34:44 +02:00
|
|
|
/// An IO operation failed.
|
|
|
|
|
#[error("an IO operation failed: {0}")]
|
|
|
|
|
IOFailed(Arc<io::Error>),
|
|
|
|
|
/// The decoding of some PNG image failed.
|
|
|
|
|
#[error("the decoding of some PNG image failed: {0}")]
|
|
|
|
|
PngDecodingFailed(Arc<png::DecodingError>),
|
|
|
|
|
/// The encoding of some PNG image failed.
|
|
|
|
|
#[error("the encoding of some PNG image failed: {0}")]
|
|
|
|
|
PngEncodingFailed(Arc<png::EncodingError>),
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The parsing of an [`Ice`](crate::Ice) test failed.
|
2025-08-27 06:02:02 +02:00
|
|
|
#[error("the ice test ({file}) is invalid: {error}")]
|
|
|
|
|
IceParsingFailed {
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The path of the test.
|
2025-08-27 06:02:02 +02:00
|
|
|
file: PathBuf,
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The parse error.
|
2025-08-27 06:02:02 +02:00
|
|
|
error: ice::ParseError,
|
|
|
|
|
},
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The execution of an [`Ice`](crate::Ice) test failed.
|
2025-08-27 06:02:02 +02:00
|
|
|
#[error("the ice test ({file}) failed")]
|
2025-08-27 06:18:23 +02:00
|
|
|
IceTestingFailed {
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The path of the test.
|
2025-08-27 06:02:02 +02:00
|
|
|
file: PathBuf,
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The [`Instruction`] that failed.
|
2025-08-27 06:02:02 +02:00
|
|
|
instruction: Instruction,
|
|
|
|
|
},
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The [`Preset`](crate::program::Preset) of a program could not be found.
|
2025-08-27 06:02:02 +02:00
|
|
|
#[error(
|
|
|
|
|
"the preset \"{name}\" does not exist (available presets: {available:?})"
|
|
|
|
|
)]
|
|
|
|
|
PresetNotFound {
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The name of the [`Preset`](crate::program::Preset).
|
2025-08-27 06:02:02 +02:00
|
|
|
name: String,
|
2025-09-12 22:53:28 +02:00
|
|
|
/// The available set of presets.
|
2025-08-27 06:02:02 +02:00
|
|
|
available: Vec<String>,
|
|
|
|
|
},
|
2025-05-29 16:34:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<io::Error> for Error {
|
|
|
|
|
fn from(error: io::Error) -> Self {
|
|
|
|
|
Self::IOFailed(Arc::new(error))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<png::DecodingError> for Error {
|
|
|
|
|
fn from(error: png::DecodingError) -> Self {
|
|
|
|
|
Self::PngDecodingFailed(Arc::new(error))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<png::EncodingError> for Error {
|
|
|
|
|
fn from(error: png::EncodingError) -> Self {
|
|
|
|
|
Self::PngEncodingFailed(Arc::new(error))
|
|
|
|
|
}
|
|
|
|
|
}
|