Enum qasmsim::error::QasmSimError
source · #[non_exhaustive]pub enum QasmSimError<'src> {
UnknownError(String),
InvalidToken {
source: &'src str,
lineno: usize,
startpos: usize,
endpos: Option<usize>,
token: Option<Tok>,
expected: Vec<String>,
},
UnexpectedEOF {
source: &'src str,
lineno: usize,
startpos: usize,
endpos: Option<usize>,
token: Option<Tok>,
expected: Vec<String>,
},
UnexpectedToken {
source: &'src str,
lineno: usize,
startpos: usize,
endpos: Option<usize>,
token: Option<Tok>,
expected: Vec<String>,
},
RedefinitionError {
source: &'src str,
symbol_name: String,
lineno: usize,
previous_lineno: usize,
},
LibraryNotFound {
source: &'src str,
libpath: String,
lineno: usize,
},
IndexOutOfBounds {
source: &'src str,
lineno: usize,
symbol_name: String,
index: usize,
size: usize,
},
SymbolNotFound {
source: &'src str,
lineno: usize,
symbol_name: String,
expected: QasmType,
},
WrongNumberOfParameters {
source: &'src str,
lineno: usize,
symbol_name: String,
are_registers: bool,
given: usize,
expected: usize,
},
UndefinedGate {
source: &'src str,
lineno: usize,
symbol_name: String,
},
TypeMismatch {
source: &'src str,
lineno: usize,
symbol_name: String,
expected: QasmType,
},
RegisterSizeMismatch {
source: &'src str,
lineno: usize,
symbol_name: String,
sizes: Vec<usize>,
},
}
Expand description
Types of errors in QasmSim. QasmSim errors contain information about the error and the location in the source code where the error happens.
QasmSimError
instances can be printed. They refer to the source code and
try to provide contextual information for fixing the problem.
Conversion between ParseError
, RuntimeError
and LinkerError
is
possible thanks to the trait From
is defined for the pair
(&'source str, T)
(see alias SrcAndErr
) for all the errors listed
above.
Examples
The error type of simulate()
is RuntimeError
.
RuntimeError
is a sourceless error in the sense it does not relate with
the concrete source code beyond the location in the AST at which the error
happens.
You can use map_err
for for capturing the error and converting it
into a QasmSimError
from its pairing with the source.
use qasmsim::{QasmSimError, parse_and_link, simulate};
let source = r#"
OPENQASM 2.0;
qreg q[2];
CX q[1], q[2]; // Notice we are indexing out of bounds here.
"#;
let program = parse_and_link(source)?;
let runtime_error = simulate(&program).expect_err("Index out of bounds");
let qasmsim_error = QasmSimError::from((source, runtime_error));
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
UnknownError(String)
A generic unknown error.
InvalidToken
Fields
Found an invalid token at some position.
UnexpectedEOF
Fields
Found an unexpected end of file.
UnexpectedToken
Fields
Found an unexpected token.
RedefinitionError
Fields
Found a redefinition of a register.
LibraryNotFound
Fields
The unability of linking a library.
IndexOutOfBounds
Fields
Use of register index that does not fit the register size.
SymbolNotFound
Fields
Use of an unknown/undeclared symbol.
WrongNumberOfParameters
Fields
The attempt of applying an operation passing the wrong number of parameters.
UndefinedGate
Fields
Use of a gate not previously defined.
TypeMismatch
Fields
Found an unexpected type of value.
RegisterSizeMismatch
Fields
Attempt of applying an operation to different sizes registers.
Trait Implementations§
source§impl<'src> Clone for QasmSimError<'src>
impl<'src> Clone for QasmSimError<'src>
source§fn clone(&self) -> QasmSimError<'src>
fn clone(&self) -> QasmSimError<'src>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<'src> Debug for QasmSimError<'src>
impl<'src> Debug for QasmSimError<'src>
source§impl Display for QasmSimError<'_>
impl Display for QasmSimError<'_>
source§impl Error for QasmSimError<'_>
impl Error for QasmSimError<'_>
1.30.0 · 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
source§impl<'src> From<(&'src str, LinkerError)> for QasmSimError<'src>
impl<'src> From<(&'src str, LinkerError)> for QasmSimError<'src>
source§fn from(source_and_error: SrcAndErr<'src, LinkerError>) -> Self
fn from(source_and_error: SrcAndErr<'src, LinkerError>) -> Self
source§impl<'src> From<(&'src str, ParseError<Location, Tok, LexicalError<Location>>)> for QasmSimError<'src>
impl<'src> From<(&'src str, ParseError<Location, Tok, LexicalError<Location>>)> for QasmSimError<'src>
source§fn from(src_and_err: SrcAndErr<'src, ParseError>) -> Self
fn from(src_and_err: SrcAndErr<'src, ParseError>) -> Self
source§impl<'src> From<(&'src str, RuntimeError)> for QasmSimError<'src>
impl<'src> From<(&'src str, RuntimeError)> for QasmSimError<'src>
source§fn from(source_and_error: SrcAndErr<'src, RuntimeError>) -> Self
fn from(source_and_error: SrcAndErr<'src, RuntimeError>) -> Self
source§impl From<String> for QasmSimError<'_>
impl From<String> for QasmSimError<'_>
source§impl<'src> Hash for QasmSimError<'src>
impl<'src> Hash for QasmSimError<'src>
source§impl<'src> PartialEq for QasmSimError<'src>
impl<'src> PartialEq for QasmSimError<'src>
source§fn eq(&self, other: &QasmSimError<'src>) -> bool
fn eq(&self, other: &QasmSimError<'src>) -> bool
self
and other
values to be equal, and is used
by ==
.