use std::path::PathBuf;
use thiserror::Error;
#[derive(Error, Debug)]
pub enum SrtmError {
#[error("IO error: {0}")]
Io(#[from] std::io::Error),
#[error("Invalid file size: {size} bytes (expected 25934402 for SRTM1 or 2884802 for SRTM3)")]
InvalidFileSize { size: usize },
#[error("Coordinates out of bounds: lat={lat}, lon={lon} (valid: lat ±60°, lon ±180°)")]
OutOfBounds { lat: f64, lon: f64 },
#[error("SRTM file not found: {path}")]
FileNotFound { path: PathBuf },
#[cfg(feature = "download")]
#[error("Failed to download tile {filename}: {reason}")]
DownloadFailed { filename: String, reason: String },
#[cfg(feature = "download")]
#[error("HTTP error: {0}")]
HttpError(#[from] reqwest::Error),
#[error("Tile not available: {filename} (not found locally, auto-download disabled)")]
TileNotAvailable { filename: String },
#[error("Invalid coordinate: {message}")]
InvalidCoordinate { message: String },
}
pub type Result<T> = std::result::Result<T, SrtmError>;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_error_display() {
let err = SrtmError::InvalidFileSize { size: 1000 };
assert!(err.to_string().contains("1000"));
let err = SrtmError::OutOfBounds {
lat: 91.0,
lon: 0.0,
};
assert!(err.to_string().contains("91"));
let err = SrtmError::FileNotFound {
path: PathBuf::from("N35E138.hgt"),
};
assert!(err.to_string().contains("N35E138.hgt"));
}
}