1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! 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>,
},
}