Skip to main content

polysim_core/
error.rs

1use thiserror::Error;
2
3/// All errors that can be produced by polysim operations.
4#[derive(Debug, Error)]
5pub enum PolySimError {
6    /// A BigSMILES string could not be parsed.
7    #[error("BigSMILES parse error: {0}")]
8    Parse(#[from] bigsmiles::ParseError),
9
10    /// The [`BuildStrategy`](crate::BuildStrategy) is invalid or not yet supported.
11    #[error("Invalid build strategy: {0}")]
12    BuildStrategy(String),
13
14    /// The BigSMILES contains no stochastic object (`{...}`), so no repeat units
15    /// are available for chain generation.
16    #[error("No stochastic object (repeat units) found in BigSMILES")]
17    NoStochasticObject,
18
19    /// The stochastic object contains the wrong number of repeat units for the
20    /// requested architecture.
21    #[error("Incompatible repeat unit count for {architecture}: got {got}, need {need}")]
22    RepeatUnitCount {
23        architecture: &'static str,
24        got: usize,
25        need: usize,
26    },
27
28    /// The weight fractions supplied to a copolymer builder do not sum to 1.0.
29    #[error("Weight fractions must sum to 1.0 (got {sum:.4})")]
30    InvalidFractions { sum: f64 },
31
32    /// A single repeat unit already uses more than 99 distinct ring-closure numbers,
33    /// which exceeds the SMILES specification.
34    #[error(
35        "Ring number overflow: the repeat unit uses {max_ring} ring closure(s), \
36         SMILES maximum is {max_supported}"
37    )]
38    RingNumberOverflow { max_ring: u32, max_supported: u32 },
39}