diff --git a/martin/src/file_config.rs b/martin/src/file_config.rs index f2dc33e37..b290356cf 100644 --- a/martin/src/file_config.rs +++ b/martin/src/file_config.rs @@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize}; use crate::config::{copy_unrecognized_config, UnrecognizedValues}; use crate::file_config::FileError::{InvalidFilePath, InvalidSourceFilePath, IoError}; -use crate::source::{Source, Sources, Xyz}; +use crate::source::{Source, Sources}; use crate::utils::{sorted_opt_map, Error, IdResolver, OneOrMany}; use crate::OneOrMany::{Many, One}; @@ -27,8 +27,8 @@ pub enum FileError { #[error(r"Unable to parse metadata in file {}: {0}", .1.display())] InvalidMetadata(String, PathBuf), - #[error(r#"Tile {0:#} not found in {1}"#)] - GetTileError(Xyz, String), + #[error(r#"Unable to aquire connection to file: {0}"#)] + AquireConnError(String), } #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] diff --git a/martin/src/mbtiles/mod.rs b/martin/src/mbtiles/mod.rs index 42641df2f..79dbb50e3 100644 --- a/martin/src/mbtiles/mod.rs +++ b/martin/src/mbtiles/mod.rs @@ -4,12 +4,13 @@ use std::path::PathBuf; use std::sync::Arc; use async_trait::async_trait; +use log::trace; use martin_mbtiles::MbtilesPool; use martin_tile_utils::TileInfo; use tilejson::TileJSON; use crate::file_config::FileError; -use crate::file_config::FileError::{GetTileError, InvalidMetadata, IoError}; +use crate::file_config::FileError::{AquireConnError, InvalidMetadata, IoError}; use crate::source::{Tile, UrlQuery}; use crate::utils::is_valid_zoom; use crate::{Error, Source, Xyz}; @@ -86,11 +87,22 @@ impl Source for MbtSource { } async fn get_tile(&self, xyz: &Xyz, _url_query: &Option) -> Result { - Ok(self + if let Some(tile) = self .mbtiles .get_tile(xyz.z, xyz.x, xyz.y) .await - .map_err(|_| GetTileError(*xyz, self.id.clone()))? - .unwrap_or_default()) + .map_err(|_| AquireConnError(self.id.clone()))? + { + Ok(tile) + } else { + trace!( + "Couldn't find tile data in {}/{}/{} of {}", + xyz.z, + xyz.x, + xyz.y, + &self.id + ); + Ok(Vec::new()) + } } } diff --git a/martin/src/pmtiles/mod.rs b/martin/src/pmtiles/mod.rs index 531b53c30..98e3a86b6 100644 --- a/martin/src/pmtiles/mod.rs +++ b/martin/src/pmtiles/mod.rs @@ -4,7 +4,7 @@ use std::path::PathBuf; use std::sync::Arc; use async_trait::async_trait; -use log::warn; +use log::{trace, warn}; use martin_tile_utils::{Encoding, Format, TileInfo}; use pmtiles::async_reader::AsyncPmTilesReader; use pmtiles::mmap::MmapBackend; @@ -12,7 +12,7 @@ use pmtiles::{Compression, TileType}; use tilejson::TileJSON; use crate::file_config::FileError; -use crate::file_config::FileError::{GetTileError, InvalidMetadata, IoError}; +use crate::file_config::FileError::{InvalidMetadata, IoError}; use crate::source::{Source, Tile, UrlQuery, Xyz}; use crate::utils::is_valid_zoom; use crate::Error; @@ -136,12 +136,21 @@ impl Source for PmtSource { async fn get_tile(&self, xyz: &Xyz, _url_query: &Option) -> Result { // TODO: optimize to return Bytes - Ok(self + if let Some(t) = self .pmtiles .get_tile(xyz.z, u64::from(xyz.x), u64::from(xyz.y)) .await - .ok_or_else(|| GetTileError(*xyz, self.id.clone()))? - .data - .to_vec()) + { + Ok(t.data.to_vec()) + } else { + trace!( + "Couldn't find tile data in {}/{}/{} of {}", + xyz.z, + xyz.x, + xyz.y, + &self.id + ); + Ok(Vec::new()) + } } }