Files
Graphite/document/document-format/src/error.rs
Dennis Kobert de11d29d8e Add document-format crate (#4234)
* Add document-format crate

* Adapt document-format to merged graph-storage and consolidate errors

* Fix resource write ordering, codec error masking, and export docs

* Remove document-format RFC; tracked in a dedicated PR

* Restructure document-format into gdd/persist/export/resource modules

Split the 963-line lib.rs by responsibility: persist path into persist.rs, resource I/O into resource.rs, export engine into export.rs. Rename the GddV1 layout struct to GddV1Layout and add a GddV1 = Gdd<GddV1Layout> alias.

* Feature-split document-format and graph-storage for minimal builds

* Address PR review: O(1) history-delta lookup and no-default-features test build

* Address PR review: propagate apply_hot_op persist error and assert resource hash

* Make decompression from archive streaming

* Share archive export body between export and export_to_bytes

* Review cleanup

* Export documents with un-retired hot ops losslessly

* Persist last_broadcast_rev in session.json, drop unused last_retired_at

* Move peer_id from manifest to session.json

* Rename gesture to interaction in document-format storage layer
2026-06-21 12:35:47 +00:00

51 lines
2.3 KiB
Rust

//! Unified error type for the `document-format` crate.
//!
//! Every fallible [`crate::Gdd`] method returns [`Result<T>`]. Variants are grouped by failure
//! domain (container I/O, codec, CRDT, format validation, export)
use document_container::ContainerError;
#[cfg(feature = "conversion")]
use graph_storage::CommitError;
use graph_storage::CrdtError;
use graphene_resource::ResourceHash;
use crate::codec::CodecError;
use crate::io::ReadError;
/// Crate-wide result alias.
pub type Result<T> = std::result::Result<T, Error>;
/// Anything that can go wrong reading, mutating, or exporting a `.gdd` document. Per the format's
/// load-time policy, any unexpected condition is a hard error rather than a silent fallback.
#[derive(Debug, thiserror::Error)]
pub enum Error {
/// Working-copy container I/O failed (read, write, or path validation).
#[error("container error: {0}")]
Container(#[from] ContainerError),
/// A typed payload could not be located or read from the container.
#[error("read error: {0}")]
Read(#[from] ReadError),
/// A payload failed to encode or decode in its recorded codec.
#[error("codec error: {0}")]
Codec(#[from] CodecError),
/// A CRDT operation was rejected while replaying a hot op or moving the undo/redo cursor.
#[error("CRDT error: {0}")]
Crdt(#[from] CrdtError),
/// Staging a runtime snapshot into the session failed (conversion or CRDT apply).
#[cfg(feature = "conversion")]
#[error("commit error: {0}")]
Commit(#[from] CommitError),
/// The manifest's `format` field is not the `.gdd` magic, so this is not a `.gdd` document.
#[error("not a .gdd document (manifest format = {found:?}, expected {expected:?})")]
WrongFormat { found: String, expected: &'static str },
/// The manifest declares a format version newer than this build can open.
#[error("unsupported format version: found {found}, max supported {max_supported}")]
UnsupportedVersion { found: u32, max_supported: u32 },
/// The requested export options are incoherent (e.g. neither registry nor history included).
#[error("invalid export options: {0}")]
InvalidExportOptions(&'static str),
/// An export marked a resource for embedding but its bytes were absent from the byte store.
#[error("embedded resource {0} missing from the byte store")]
MissingResource(ResourceHash),
}