1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
use std::fmt;
/// Errors returned by the explicit polyglot persistence boundary.
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum PolyglotError {
/// A collection, database, namespace, or document identifier was rejected.
#[error("invalid {kind}: {reason}")]
InvalidIdentifier {
/// Identifier category.
kind: &'static str,
/// Stable, credential-free failure detail.
reason: &'static str,
},
/// An adapter configuration is unsafe or incomplete.
#[error("invalid {backend} configuration: {reason}")]
InvalidConfiguration {
/// Backend being configured.
backend: &'static str,
/// Stable, credential-free failure detail.
reason: &'static str,
},
/// A record with the requested identifier already exists.
#[error("document already exists")]
Conflict,
/// A record required by a mutating operation does not exist.
#[error("document not found")]
NotFound,
/// A model could not be serialized or decoded.
#[error("serialization failed: {0}")]
Serialization(String),
/// A backend driver returned an error.
#[error("{backend} operation failed: {message}")]
Driver {
/// Backend that returned the error.
backend: &'static str,
/// Error text with secrets excluded by the adapter.
message: String,
},
/// A response exceeded the adapter's configured memory bound.
#[error("{backend} response exceeded the {limit_bytes}-byte limit")]
ResponseTooLarge {
/// Backend that returned the response.
backend: &'static str,
/// Maximum accepted response size.
limit_bytes: usize,
},
/// The backend cannot represent a value through the portable API.
#[error("{backend} value type is unsupported: {kind}")]
UnsupportedValue {
/// Backend that produced the value.
backend: &'static str,
/// Backend type name.
kind: String,
},
/// Work delegated to a blocking worker could not complete.
#[error("{backend} worker failed: {message}")]
Worker {
/// Backend whose worker stopped.
backend: &'static str,
/// Join or lock failure detail.
message: String,
},
}
impl PolyglotError {
#[cfg(any(
feature = "duckdb",
feature = "mongodb",
feature = "surrealdb",
feature = "turso"
))]
pub(crate) fn driver(backend: &'static str, error: impl fmt::Display) -> Self {
Self::Driver {
backend,
message: error.to_string(),
}
}
pub(crate) fn serialization(error: impl fmt::Display) -> Self {
Self::Serialization(error.to_string())
}
/// Converts a redacted model-codec failure into the public error contract.
#[doc(hidden)]
pub fn serialization_public(error: impl fmt::Display) -> Self {
Self::serialization(error)
}
}