Skip to main content

moq_archive/
error.rs

1/// Errors from encoding, decoding, or storing recording objects.
2#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
3#[non_exhaustive]
4pub enum Error {
5	/// The backing object store failed.
6	#[error("object store: {0}")]
7	Store(String),
8
9	/// No object exists at this key.
10	#[error("not found: {0}")]
11	NotFound(String),
12
13	/// The recording format version is not 1.
14	#[error("unknown version {0}")]
15	Version(u64),
16
17	/// A group ID, segment ID, or frame timestamp is outside 0 through 2^53 - 1.
18	#[error("{0} exceeds the recording id range")]
19	Id(u64),
20
21	/// `.info` timescale is not in 1 through 2^53 - 1.
22	#[error("timescale {0} is outside 1..=9007199254740991")]
23	Timescale(u64),
24
25	/// An existing `.info` has a different priority.
26	#[error("priority {existing} does not match {intended}")]
27	Priority { existing: u8, intended: u8 },
28
29	/// An existing `.info` has a different timescale.
30	#[error("timescale {existing} does not match {intended}")]
31	TimescaleMismatch { existing: u64, intended: u64 },
32
33	/// The object has no groups.
34	#[error("empty object")]
35	Empty,
36
37	/// Group sequences are not strictly ascending.
38	#[error("group sequences are not strictly ascending")]
39	Sequence,
40
41	/// A group range is empty, reversed, or does not match an object's table.
42	#[error("invalid or mismatched group bounds {smallest}..={largest}")]
43	Bounds { smallest: u64, largest: u64 },
44
45	/// The binary table is truncated, overlapping, gapped, or out of range.
46	#[error("malformed table")]
47	Table,
48
49	/// Arithmetic overflowed while encoding or decoding.
50	#[error("overflow")]
51	Overflow,
52
53	/// The track name is empty or its encoding is not canonical.
54	#[error("invalid track name")]
55	Track,
56
57	/// An object path is not a recording key.
58	#[error("invalid path: {0}")]
59	Path(String),
60
61	/// A backend returned a directory from the flat object listing API.
62	#[error("directory listing is unsupported: {0}")]
63	Directory(String),
64
65	/// A pagination continuation was passed to streaming list.
66	#[error("continuation query requires list_paginated")]
67	Pagination,
68
69	/// A create collided with different object bytes.
70	#[error("conflicting object: {0}")]
71	Conflict(String),
72
73	/// `.info` JSON is malformed.
74	#[error("json: {0}")]
75	Json(String),
76}
77
78impl From<object_store::Error> for Error {
79	fn from(err: object_store::Error) -> Self {
80		match err {
81			object_store::Error::NotFound { path, .. } => Self::NotFound(path),
82			other => Self::Store(other.to_string()),
83		}
84	}
85}
86
87impl From<serde_json::Error> for Error {
88	fn from(err: serde_json::Error) -> Self {
89		Self::Json(err.to_string())
90	}
91}
92
93/// A [`Result`](std::result::Result) using this crate's [`Error`].
94pub type Result<T> = std::result::Result<T, Error>;