Skip to main content

micromegas_object_cache/range_cache/
error.rs

1use micromegas_tracing::prelude::*;
2
3/// Errors returned by [`RangeCache`] that callers may want to handle distinctly.
4#[derive(Debug, thiserror::Error)]
5pub enum RangeError {
6    /// The requested range extends past the end of the object.
7    #[error("requested range end {requested_end} exceeds object size {file_size}")]
8    OutOfBounds { requested_end: u64, file_size: u64 },
9}
10
11/// Which caller is invoking `RangeCache::stream_ranges`, selecting which of
12/// the two distinct `range_cache_get_range_error` / `range_cache_get_ranges_error`
13/// counters is emitted on an upfront validation failure or a mid-stream fetch
14/// error. `stream_ranges` is the single fill path behind both `get_range`/
15/// `get_range_handler` (`Range`) and `get_ranges`/`post_ranges_handler`
16/// (`Ranges`), so the tag keeps the two metric names emitting exactly as they
17/// did before those call sites shared one implementation.
18#[derive(Copy, Clone, Debug, PartialEq, Eq)]
19pub enum StreamRangesCaller {
20    Range,
21    Ranges,
22}
23
24impl StreamRangesCaller {
25    pub(super) fn emit_error_metric(self) {
26        match self {
27            StreamRangesCaller::Range => imetric!("range_cache_get_range_error", "count", 1_u64),
28            StreamRangesCaller::Ranges => {
29                imetric!("range_cache_get_ranges_error", "count", 1_u64)
30            }
31        }
32    }
33}