#[non_exhaustive]pub enum TouchstoneError {
Show 20 variants
Parse {
context: TouchstoneErrorContext,
source: Box<TouchstoneError>,
},
Io(Error),
InvalidUtf8(Utf8Error),
MissingFileType {
source_name: String,
},
UnsupportedFileType {
file_type: String,
},
InvalidPortCount {
file_type: String,
},
MultipleOptionLines,
InvalidDataLineParts {
expected: usize,
actual: usize,
},
InvalidNumber {
token: String,
},
UnsupportedFrequencyUnit {
unit: String,
},
UnsupportedFormat {
format: String,
},
InvalidKeywordLine {
line: String,
},
UnsupportedVersion {
version: String,
},
InvalidNumberOfPorts {
value: String,
},
NumberOfPortsMismatch {
keyword_ports: i32,
extension_ports: i32,
},
TwoPortDataOrderForNonTwoPort,
UnsupportedTwoPortDataOrder {
order: String,
},
InvalidNumberOfFrequencies {
value: String,
},
NumberOfFrequenciesMismatch {
expected: usize,
actual: usize,
},
UnsupportedMatrixFormat {
format: String,
},
}Expand description
Error returned when Touchstone data cannot be read or parsed.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Parse
A parse error with source-location context.
Fields
context: TouchstoneErrorContextSource location where the parser detected the error.
source: Box<TouchstoneError>Structured root error.
Io(Error)
The source file could not be read.
InvalidUtf8(Utf8Error)
In-memory bytes were not valid UTF-8 Touchstone text.
MissingFileType
The source name did not include a file extension.
UnsupportedFileType
The source extension is not a supported Touchstone file type.
InvalidPortCount
The Touchstone extension did not contain a valid port count.
MultipleOptionLines
The file contained more than one option line.
InvalidDataLineParts
A data line did not contain the expected number of values.
Fields
InvalidNumber
A numeric token could not be parsed as f64.
UnsupportedFrequencyUnit
The frequency unit is not supported.
UnsupportedFormat
The network data format is not supported.
InvalidKeywordLine
A keyword line was malformed.
UnsupportedVersion
The Touchstone version is not supported.
InvalidNumberOfPorts
The [Number of Ports] value was not a valid integer.
NumberOfPortsMismatch
The [Number of Ports] value did not match the source extension.
Fields
TwoPortDataOrderForNonTwoPort
[Two-Port Data Order] was present for a network other than .s2p.
UnsupportedTwoPortDataOrder
The [Two-Port Data Order] value is not supported.
InvalidNumberOfFrequencies
The [Number of Frequencies] value was not a valid integer.
NumberOfFrequenciesMismatch
The parsed data line count did not match [Number of Frequencies].
Fields
UnsupportedMatrixFormat
Matrix format values other than Full are not supported.
Implementations§
Source§impl TouchstoneError
impl TouchstoneError
Sourcepub fn context(&self) -> Option<&TouchstoneErrorContext>
pub fn context(&self) -> Option<&TouchstoneErrorContext>
Return parser source-location context when this error has it.
§Examples
let error =
touchstone::Network::from_str("uploaded.s1p", "# GHz S RI R 50\n1.0 0.1\n")
.unwrap_err();
let context = error.context().unwrap();
assert_eq!(context.source_name, "uploaded.s1p");
assert_eq!(context.line_number, Some(2));
assert_eq!(context.line.as_deref(), Some("1.0 0.1"));Sourcepub fn root_cause(&self) -> &TouchstoneError
pub fn root_cause(&self) -> &TouchstoneError
Return the deepest structured error wrapped by parser context.
§Examples
use touchstone::{Network, TouchstoneError};
let error = Network::from_str("uploaded.s1p", "# GHz S RI R 50\n1.0 0.1\n").unwrap_err();
assert!(matches!(
error.root_cause(),
TouchstoneError::InvalidDataLineParts {
expected: 3,
actual: 2
}
));Trait Implementations§
Source§impl Debug for TouchstoneError
impl Debug for TouchstoneError
Source§impl Display for TouchstoneError
impl Display for TouchstoneError
Source§impl Error for TouchstoneError
impl Error for TouchstoneError
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()