rullst_orm/polyglot/
error.rs1use std::fmt;
2
3#[derive(Debug, thiserror::Error)]
5#[non_exhaustive]
6pub enum PolyglotError {
7 #[error("invalid {kind}: {reason}")]
9 InvalidIdentifier {
10 kind: &'static str,
12 reason: &'static str,
14 },
15 #[error("invalid {backend} configuration: {reason}")]
17 InvalidConfiguration {
18 backend: &'static str,
20 reason: &'static str,
22 },
23 #[error("document already exists")]
25 Conflict,
26 #[error("document not found")]
28 NotFound,
29 #[error("serialization failed: {0}")]
31 Serialization(String),
32 #[error("{backend} operation failed: {message}")]
34 Driver {
35 backend: &'static str,
37 message: String,
39 },
40 #[error("{backend} response exceeded the {limit_bytes}-byte limit")]
42 ResponseTooLarge {
43 backend: &'static str,
45 limit_bytes: usize,
47 },
48 #[error("{backend} value type is unsupported: {kind}")]
50 UnsupportedValue {
51 backend: &'static str,
53 kind: String,
55 },
56 #[error("{backend} worker failed: {message}")]
58 Worker {
59 backend: &'static str,
61 message: String,
63 },
64}
65
66impl PolyglotError {
67 #[cfg(any(
68 feature = "duckdb",
69 feature = "mongodb",
70 feature = "surrealdb",
71 feature = "turso"
72 ))]
73 pub(crate) fn driver(backend: &'static str, error: impl fmt::Display) -> Self {
74 Self::Driver {
75 backend,
76 message: error.to_string(),
77 }
78 }
79
80 pub(crate) fn serialization(error: impl fmt::Display) -> Self {
81 Self::Serialization(error.to_string())
82 }
83
84 #[doc(hidden)]
86 pub fn serialization_public(error: impl fmt::Display) -> Self {
87 Self::serialization(error)
88 }
89}