cqlib_core/visualization/error.rs
1// This code is part of Cqlib.
2//
3// (C) Copyright China Telecom Quantum Group 2026
4//
5// This code is licensed under the Apache License, Version 2.0. You may
6// obtain a copy of this license in the LICENSE.txt file in the root directory
7// of this source tree or at http://www.apache.org/licenses/LICENSE-2.0.
8//
9// Any modifications or derivative works of this code must retain this
10// copyright notice, and modified files need to carry a notice indicating
11// that they have been altered from the originals.
12
13//! Visualization error types.
14//!
15//! Error types shared by visualization IR building and rendering backends.
16
17use crate::circuit::error::CircuitError;
18use thiserror::Error;
19
20/// Comprehensive error type for the visualization module.
21///
22/// This enum captures errors that can occur during IR construction, input validation,
23/// SVG rendering, and file output across circuit, state, and result visualization.
24#[derive(Debug, Error)]
25pub enum VisualizationError {
26 /// Thrown when circuit preprocessing fails before visualization IR construction.
27 #[error("circuit preprocessing failed: {0}")]
28 CircuitBuild(#[from] CircuitError),
29
30 /// Thrown when an operation references a qubit that is not present in the circuit qubit list.
31 #[error("operation references unknown qubit Q{0}")]
32 UnknownQubit(u32),
33
34 /// Thrown when a symbolic parameter index points outside the circuit parameter table.
35 #[error("parameter index {index} out of bounds (len={len})")]
36 ParameterIndexOutOfBounds {
37 /// Invalid parameter index referenced by the operation.
38 index: u32,
39 /// Number of parameters currently registered on the circuit.
40 len: usize,
41 },
42
43 /// Thrown when SVG parsing or rasterization fails while converting SVG-first outputs.
44 #[error("svg rendering failed: {0}")]
45 SvgRenderFailed(String),
46
47 /// Thrown when input data for a visualization routine is invalid or inconsistent.
48 #[error("invalid visualization input: {0}")]
49 InvalidInput(String),
50
51 /// Thrown when writing visualization output to disk fails.
52 #[error(transparent)]
53 Io(#[from] std::io::Error),
54}