use osproxy_core::json::JsonError;
use osproxy_core::FieldName;
use thiserror::Error;
#[non_exhaustive]
#[derive(Debug, Error, PartialEq, Eq)]
pub enum RewriteError {
#[error("document body is not a JSON object")]
NotAnObject,
#[error("document body is not valid JSON")]
InvalidJson,
#[error("client document already contains reserved field")]
ReservedFieldCollision {
field: FieldName,
},
#[error("path does not resolve to a scalar value in the document")]
PathNotScalar {
path: String,
},
#[error("unsupported id-template placeholder")]
UnsupportedPlaceholder {
placeholder: String,
},
#[error("malformed _bulk action line")]
MalformedBulkAction,
#[error("id template is not reversible: needs exactly one body placeholder")]
IrreversibleIdTemplate,
#[error("search construct bypasses the partition filter: {construct}")]
Unfilterable {
construct: &'static str,
},
}
impl From<JsonError> for RewriteError {
fn from(err: JsonError) -> Self {
match err {
JsonError::Invalid => Self::InvalidJson,
JsonError::NotAnObject => Self::NotAnObject,
JsonError::PathNotScalar { path } => Self::PathNotScalar { path },
}
}
}