Skip to main content

ogc_cql2/
error.rs

1// SPDX-License-Identifier: Apache-2.0
2
3#![warn(missing_docs)]
4
5//! Errors raised from this library.
6//!
7
8use peg::{error::ParseError, str::LineCol};
9use std::{
10    array::TryFromSliceError,
11    borrow::Cow,
12    num::{ParseIntError, TryFromIntError},
13};
14use thiserror::Error;
15
16/// Variants of error raised from this library.
17#[derive(Debug, Error)]
18pub enum MyError {
19    /// Input/Output related error.
20    #[error("I/O error: {0}")]
21    IO(#[from] std::io::Error),
22
23    /// Date, time + timestamp (`jiff`) parsing error.
24    #[error("Date-Time error: {0}")]
25    Time(#[from] jiff::Error),
26
27    /// Text-encoding (`peg`) related error.
28    #[error("PEG error: {0:?}")]
29    Text(ParseError<LineCol>),
30
31    /// JSON-encoding (`serde`) related error
32    #[error("Json [Try]From error: {0}")]
33    Json(#[from] serde_json::Error),
34
35    /// GEOS related error.
36    #[error("Geos error: {0}")]
37    Geos(#[from] geos::Error),
38
39    /// Coordinate conversion results in loss of precision.
40    #[error("Converting {0} to `f64` will result in loss of precision")]
41    PrecisionLoss(Cow<'static, str>),
42
43    /// CRS construction error.
44    #[error("CRS creation error: {0}")]
45    CRS(#[from] proj::ProjCreateError),
46
47    /// Coordinate transformation (`proj`) related error.
48    #[error("Proj error: {0}")]
49    Proj(#[from] proj::ProjError),
50
51    /// Runtime error.
52    #[error("Runtime error: {0}")]
53    Runtime(Cow<'static, str>),
54
55    /// CSV error.
56    #[error("CSV error: {0}")]
57    CSV(#[from] csv::Error),
58
59    /// SqlX error.
60    #[error("SQLx error: {0}")]
61    SQL(#[from] sqlx::Error),
62
63    /// Byte-array to integer conversion error.
64    #[error("Conversion (bytes -> int) error: {0}")]
65    Conv(#[from] TryFromIntError),
66
67    /// String to integer conversion error.
68    #[error("Conversion (str -> int) error: {0}")]
69    Conv2(#[from] ParseIntError),
70
71    /// Byte-array to float conversion error.
72    #[error("Conversion (slice) error: {0}")]
73    Slice(#[from] TryFromSliceError),
74}