use crate::{BitRange, Format, HierarchyPath, Signal, Time};
#[derive(Debug, Clone, thiserror::Error)]
#[error("invalid hierarchy path at byte {offset}: {message}")]
pub struct PathError {
pub offset: usize,
pub message: String,
}
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum PathFormatError {
#[error("path component cannot be represented in Verilog: {component:?}")]
NotRepresentable {
component: String,
},
}
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum SliceError {
#[error("HDL range {range:?} does not match signal width {width}")]
HdlRangeWidthMismatch {
range: BitRange,
width: u32,
},
#[error("HDL slice [{msb}:{lsb}] is outside {range:?}")]
HdlOutOfBounds {
range: BitRange,
msb: i64,
lsb: i64,
},
#[error("HDL slice [{msb}:{lsb}] has the opposite direction to {range:?}")]
HdlDirectionMismatch {
range: BitRange,
msb: i64,
lsb: i64,
},
#[error("only bit-vector signals can be sliced")]
NotBits,
#[error("invalid slice [{msb}:{lsb}]")]
InvalidRange {
msb: u32,
lsb: u32,
},
#[error("slice [{msb}:{lsb}] is outside signal width {width}")]
OutOfBounds {
width: u32,
msb: u32,
lsb: u32,
},
}
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum CompositionError {
#[error("a composition needs at least one part")]
Empty,
#[error("composition part {part} has zero width")]
EmptyPart {
part: usize,
signal: Signal,
},
#[error("composition part {part} is not a bit vector")]
NotBits {
part: usize,
signal: Signal,
},
#[error("composition width exceeds u32::MAX")]
WidthOverflow,
}
#[derive(Debug, Clone, thiserror::Error)]
#[non_exhaustive]
pub enum LookupError {
#[error(transparent)]
InvalidPath(
#[from]
PathError,
),
#[error("hierarchy item was not found: {path}")]
NotFound {
path: HierarchyPath,
},
#[error("hierarchy lookup is ambiguous ({matches} matches): {path}")]
Ambiguous {
path: HierarchyPath,
matches: usize,
},
#[error("variable has no waveform signal: {path}")]
NoSignal {
path: HierarchyPath,
},
#[error(transparent)]
InvalidSlice(
#[from]
SliceError,
),
}
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
#[error(transparent)]
InvalidComposition(#[from] CompositionError),
#[error("I/O error: {0}")]
Io(
#[from]
std::io::Error,
),
#[error("unknown waveform format")]
UnknownFormat,
#[error("unknown Ondas backend: {backend}")]
UnknownBackend {
backend: String,
},
#[error("no available backend for {format:?}")]
NoBackend {
format: Format,
},
#[error("backend {backend} is unavailable: {message}")]
BackendUnavailable {
backend: String,
message: String,
},
#[error("backend {backend} does not support {format:?}")]
BackendDoesNotSupport {
backend: String,
format: Format,
},
#[error("backend {backend} does not support {input:?} input")]
UnsupportedInput {
backend: String,
input: InputKind,
},
#[error("unsupported {format:?} feature in {backend} during {operation}: {message}")]
UnsupportedFeature {
format: Format,
backend: String,
operation: &'static str,
message: String,
},
#[error("malformed {format:?} waveform read by {backend}: {message}")]
Malformed {
format: Format,
backend: String,
message: String,
},
#[error("non-ASCII string at {time:?} in {format:?} waveform read by {backend}")]
NonAsciiString {
format: Format,
backend: String,
time: Time,
},
#[error("selection index {index} is outside 0..{len}")]
InvalidSelectionIndex {
index: usize,
len: usize,
},
#[error(
"cannot read {requested:?} in a query at {current:?}; only the current tick and its checked predecessor are available"
)]
InvalidQueryTime {
requested: Time,
current: Time,
},
#[error("trace range {range:?} does not cover {requested:?}")]
TraceCoverage {
requested: Time,
range: crate::TimeRange,
},
#[error("signal does not belong to this waveform")]
InvalidSignal {
signal: Signal,
},
#[error("signal encoding is not supported: {signal:?}")]
UnsupportedSignal {
signal: Signal,
},
#[error("backend {backend} failed during {operation}: {message}")]
Backend {
backend: String,
operation: &'static str,
message: String,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[non_exhaustive]
pub enum InputKind {
File,
Bytes,
}