#![allow(unused_assignments, reason = "these unused fields are useful in debug printing")]
#[derive(Clone, Debug, PartialEq, thiserror::Error, miette::Diagnostic)]
#[non_exhaustive]
pub enum Error {
#[diagnostic(
code(google_maps::places_new::mutually_exclusive_location_fields),
severity(Error),
help(
"use either location_bias OR location_restriction, not both. \
bias influences ranking while restriction hard-limits results"
)
)]
#[error("cannot set both location bias and location restriction")]
MutuallyExclusiveLocationFields {
#[source_code]
debug: String,
#[label("both fields were set, but only one is allowed")]
span: (usize, usize),
},
#[diagnostic(
code(google_maps::places::decimal_error),
severity(Error),
help("check that decimal values are within valid range and properly formatted")
)]
#[error("decimal operation error: {source}")]
Decimal {
#[from]
#[source]
source: rust_decimal::Error,
},
#[diagnostic(
code(google_maps::places_new::unknown_error),
severity(Error),
help("the request may succeed if you try again after a brief delay")
)]
#[error("unknown server error")]
UnknownError,
#[error("an error that can never happen")]
StdConvertInfallible {
#[from]
#[source]
source: std::convert::Infallible,
},
}
impl std::convert::From<Error> for crate::Error {
fn from(error: Error) -> Self {
Self::PlacesNew { source: error.into() }
}
}
impl crate::traits::ClassifiableError<'_, Self> for Error {
fn classify(&self) -> crate::ClassifiedError<'_, Self> {
if self == &Self::UnknownError {
crate::ClassifiedError::Transient(self)
} else {
crate::ClassifiedError::Permanent(self)
}
}
}