#![allow(unused_assignments, reason = "these unused fields are useful in debug printing")]
use miette::SourceSpan;
#[derive(Clone, Debug, Eq, PartialEq, thiserror::Error, miette::Diagnostic)]
#[non_exhaustive]
pub enum Error {
#[error("Place has no photos available")]
#[diagnostic(
code(google_maps::places::place_photos::no_photos),
help("Ensure the place has photos and that 'photos' was included in the field mask")
)]
PlaceHasNoPhotos {
#[source_code]
place_id: Option<String>,
#[label("This place has no associated photos")]
span: SourceSpan,
},
#[error("Failed to download photo from {url}")]
#[diagnostic(
code(google_maps::places::place_photos::download_failed),
help("The photo URI may have expired. Try fetching a fresh photo URI from a place query.")
)]
PhotoDownloadFailed {
status: u16,
#[source_code]
url: String,
#[label("HTTP request to this URI failed")]
span: SourceSpan,
},
#[error("Photo request missing required dimension constraints")]
#[diagnostic(
code(google_maps::places::place_photos::missing_dimensions),
help("Specify at least one of max_width_px or max_height_px (range: 1-4800 pixels)")
)]
MissingPhotoDimensions {
#[source_code]
debug: String,
#[label("Neither max_width_px nor max_height_px was specified")]
span: SourceSpan,
},
#[error("Invalid photo width constraint: {width} pixels")]
#[diagnostic(
code(google_maps::places::place_photos::invalid_width),
help("max_width_px must be between 1 and 4800 pixels (inclusive)")
)]
InvalidPhotoWidth {
width: u32,
#[source_code]
debug: String,
#[label("This width is outside the valid range of 1-4800")]
span: SourceSpan,
},
#[error("Invalid photo height constraint: {height} pixels")]
#[diagnostic(
code(google_maps::places::place_photos::invalid_height),
help("max_height_px must be between 1 and 4800 pixels (inclusive)")
)]
InvalidPhotoHeight {
height: u32,
#[source_code]
debug: String,
#[label("This height is outside the valid range of 1-4800")]
span: SourceSpan,
},
#[error("Failed to decode image")]
#[diagnostic(
code(google_maps::places::place_photos::image_decode_failed),
help("Ensure the image was downloaded completely and is in a supported format (JPEG, PNG, WebP)")
)]
ImageDecodeError {
message: String,
},
}
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> {
crate::ClassifiedError::Permanent(self)
}
}