Skip to main content

engine/
error.rs

1//! Error types for the Engine.
2
3use crate::core::metadata::Name;
4use crate::core::object_id::ObjectId;
5use crate::filesystem::path::VirtualPath;
6use crate::security::authorization::{ActorId, Operation};
7
8/// The error type for all Engine operations.
9#[derive(Debug, thiserror::Error, PartialEq, Eq)]
10pub enum Error {
11    /// The referenced object does not exist.
12    #[error("object {0} does not exist")]
13    ObjectNotFound(ObjectId),
14
15    /// No object exists at the given path.
16    #[error("path `{0}` does not exist")]
17    PathNotFound(VirtualPath),
18
19    /// The operation requires a directory, but the object is not one.
20    #[error("object {0} is not a directory")]
21    NotADirectory(ObjectId),
22
23    /// The operation requires a file, but the object is not one.
24    #[error("object {0} is not a file")]
25    NotAFile(ObjectId),
26
27    /// A sibling object with the same name already exists.
28    #[error("an object named `{name}` already exists in directory {directory}")]
29    NameAlreadyExists {
30        /// The conflicting name.
31        name: Name,
32        /// The directory that already contains the name.
33        directory: ObjectId,
34    },
35
36    /// The string is not a valid object name.
37    #[error("`{0}` is not a valid object name")]
38    InvalidName(String),
39
40    /// The string is not a valid virtual path.
41    #[error("`{0}` is not a valid virtual path")]
42    InvalidPath(String),
43
44    /// The string is not a valid metadata key.
45    #[error("`{0}` is not a valid metadata key")]
46    InvalidMetadataKey(String),
47
48    /// Moving the object into itself or one of its descendants would create a cycle.
49    #[error("object {0} cannot be moved into itself or one of its descendants")]
50    CyclicMove(ObjectId),
51
52    /// Copying the object into itself or one of its descendants would recurse forever.
53    #[error("object {0} cannot be copied into itself or one of its descendants")]
54    CyclicCopy(ObjectId),
55
56    /// Resolving a symbolic link exceeded the depth cap (a loop).
57    #[error("too many levels of symbolic links: {0}")]
58    SymlinkLoop(String),
59
60    /// The object still has a parent; detach it before attaching elsewhere.
61    #[error("object {0} is already attached")]
62    AttachedObject(ObjectId),
63
64    /// Attaching the object beneath itself (or one of its descendants) would
65    /// create a parent cycle.
66    #[error("object {0} cannot be attached beneath itself or one of its descendants")]
67    CyclicAttach(ObjectId),
68
69    /// The root object cannot be moved.
70    #[error("the root object cannot be moved")]
71    RootMove,
72
73    /// The root object cannot be deleted.
74    #[error("the root object cannot be deleted")]
75    RootDelete,
76
77    /// The root object cannot be detached.
78    #[error("the root object cannot be detached")]
79    RootDetach,
80
81    /// The current actor is not authorized to perform the operation.
82    #[error("Operation not permitted")]
83    NotAuthorized {
84        /// The object the operation targeted.
85        object: ObjectId,
86        /// The operation that was denied.
87        operation: Operation,
88        /// The actor that performed the operation, if any.
89        actor: Option<ActorId>,
90    },
91}