vce-engine 0.1.1

The generic state substrate of the Virtual Computing Engine (VCE)
Documentation
//! Error types for the Engine.

use crate::core::metadata::Name;
use crate::core::object_id::ObjectId;
use crate::filesystem::path::VirtualPath;
use crate::security::authorization::{ActorId, Operation};

/// The error type for all Engine operations.
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum Error {
    /// The referenced object does not exist.
    #[error("object {0} does not exist")]
    ObjectNotFound(ObjectId),

    /// No object exists at the given path.
    #[error("path `{0}` does not exist")]
    PathNotFound(VirtualPath),

    /// The operation requires a directory, but the object is not one.
    #[error("object {0} is not a directory")]
    NotADirectory(ObjectId),

    /// The operation requires a file, but the object is not one.
    #[error("object {0} is not a file")]
    NotAFile(ObjectId),

    /// A sibling object with the same name already exists.
    #[error("an object named `{name}` already exists in directory {directory}")]
    NameAlreadyExists {
        /// The conflicting name.
        name: Name,
        /// The directory that already contains the name.
        directory: ObjectId,
    },

    /// The string is not a valid object name.
    #[error("`{0}` is not a valid object name")]
    InvalidName(String),

    /// The string is not a valid virtual path.
    #[error("`{0}` is not a valid virtual path")]
    InvalidPath(String),

    /// The string is not a valid metadata key.
    #[error("`{0}` is not a valid metadata key")]
    InvalidMetadataKey(String),

    /// Moving the object into itself or one of its descendants would create a cycle.
    #[error("object {0} cannot be moved into itself or one of its descendants")]
    CyclicMove(ObjectId),

    /// Copying the object into itself or one of its descendants would recurse forever.
    #[error("object {0} cannot be copied into itself or one of its descendants")]
    CyclicCopy(ObjectId),

    /// Resolving a symbolic link exceeded the depth cap (a loop).
    #[error("too many levels of symbolic links: {0}")]
    SymlinkLoop(String),

    /// The object still has a parent; detach it before attaching elsewhere.
    #[error("object {0} is already attached")]
    AttachedObject(ObjectId),

    /// Attaching the object beneath itself (or one of its descendants) would
    /// create a parent cycle.
    #[error("object {0} cannot be attached beneath itself or one of its descendants")]
    CyclicAttach(ObjectId),

    /// The root object cannot be moved.
    #[error("the root object cannot be moved")]
    RootMove,

    /// The root object cannot be deleted.
    #[error("the root object cannot be deleted")]
    RootDelete,

    /// The root object cannot be detached.
    #[error("the root object cannot be detached")]
    RootDetach,

    /// The current actor is not authorized to perform the operation.
    #[error("Operation not permitted")]
    NotAuthorized {
        /// The object the operation targeted.
        object: ObjectId,
        /// The operation that was denied.
        operation: Operation,
        /// The actor that performed the operation, if any.
        actor: Option<ActorId>,
    },
}