use crate::Key; use jacquard_api::com_atproto::{ repo::apply_writes::ApplyWritesError, sync::get_latest_commit::GetLatestCommitError, }; use jacquard_common::xrpc::XrpcError; /// Failures callers can classify without inspecting messages or downcasting. #[derive(Debug, thiserror::Error)] pub enum Error { /// The host supplies the store's error type; preserve it as the source. #[error("storage failed: {0}")] Store(#[source] folio_transport::BoxError), #[error(transparent)] Transport(#[from] folio_transport::Error), #[error(transparent)] InvalidIdentifier(#[from] jacquard_common::types::string::AtStrError), #[error("expected a Space URI: at://DID/space/TYPE/KEY")] InvalidSpaceUri, #[error("Space repository I/O is not implemented yet")] SpaceUnsupported, #[error(transparent)] Record(#[from] crate::RecordError), #[error(transparent)] Blob(#[from] crate::BlobError), #[error(transparent)] Discovery(#[from] DiscoveryError), #[error(transparent)] Sync(#[from] SyncError), #[error("conflict resolution failed: {0}")] ConflictResolution(#[source] folio_transport::BoxError), #[error("load the collection with get or list before editing this record")] CollectionNotLoaded, #[error("invalid HTTP request: {0}")] Http(#[from] folio_transport::http::Error), #[error("invalid JSON: {0}")] Json(#[from] serde_json::Error), #[error("invalid CID: {0}")] Cid(#[from] ipld_core::cid::Error), #[error("applying remote writes failed: {0}")] ApplyWrites(#[from] XrpcError), #[error("listing remote records failed: {0}")] ListRecords(#[from] Box>), #[error("reading the remote checkpoint failed: {0}")] LatestCommit(#[from] XrpcError), } #[derive(Debug, thiserror::Error)] pub enum DiscoveryError { #[error("PDS discovery currently requires a did:plc account")] UnsupportedDid, #[error("DID resolution failed: HTTP {0}")] HttpStatus(folio_transport::http::StatusCode), #[error("DID document identifies a different account")] DidMismatch, #[error("account DID document has no PDS")] MissingPds, #[error("invalid PDS URL: {0}")] InvalidUrl(#[from] url::ParseError), } #[derive(Debug, thiserror::Error)] pub enum SyncError { #[error("remote record changed: {}/{}; local edit kept", .0.collection, .0.rkey)] Conflict(Key), #[error("write receipt is missing commit metadata; local edits kept")] UnconfirmedWrite, #[error("local repository changed; try the operation again")] LocalChanged, #[error("remote repository changed during download; synchronize again")] RemoteChanged, #[error("PDS returned a record outside the requested collection")] InvalidRecordUri, #[error("record bytes do not match the PDS record CID")] RecordCidMismatch, #[error("PDS repeated a record cursor")] RepeatedCursor, }