iced-yoda/test/src/error.rs

63 lines
1.8 KiB
Rust
Raw Normal View History

use crate::Instruction;
use crate::ice;
2025-05-29 16:34:44 +02:00
use std::io;
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).
#[error("no matching widget was found for the selector: {selector}")]
NotFound { selector: String },
#[error("the matching target is not visible: {target:?}")]
NotVisible {
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>),
#[error("the ice test ({file}) is invalid: {error}")]
IceParsingFailed {
file: PathBuf,
error: ice::ParseError,
},
#[error("the ice test ({file}) failed")]
IceFailed {
file: PathBuf,
instruction: Instruction,
},
#[error(
"the preset \"{name}\" does not exist (available presets: {available:?})"
)]
PresetNotFound {
name: String,
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))
}
}