mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-12-01 07:24:56 -10:00
66 lines
2.9 KiB
Rust
66 lines
2.9 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 document_graph_storage::CommitError;
|
|
use document_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 container has no manifest, cannot be opened.
|
|
#[error("container has no manifest")]
|
|
MissingManifest,
|
|
/// 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),
|
|
/// A migration of the document failed while it opened.
|
|
#[cfg(feature = "migrations")]
|
|
#[error("migration error: {0}")]
|
|
Migration(#[from] migration_runner::RunnerError),
|
|
/// 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),
|
|
/// A packet for the collaboration session failed to encode.
|
|
#[cfg(feature = "network")]
|
|
#[error("network error: {0}")]
|
|
Network(#[from] peer_transport::PacketError),
|
|
/// The room knows this device by its peer, so the user can't change.
|
|
#[cfg(feature = "network")]
|
|
#[error("the user cannot change while the document is connected")]
|
|
UserChangeWhileConnected,
|
|
}
|