foundationdb/directory/error.rs
1// Copyright 2018 foundationdb-rs developers, https://github.com/Clikengo/foundationdb-rs/graphs/contributors
2// Copyright 2013-2018 Apple, Inc and the FoundationDB project authors.
3//
4// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
5// http://apache.org/licenses/LICENSE-2.0> or the MIT license <LICENSE-MIT or
6// http://opensource.org/licenses/MIT>, at your option. This file may not be
7// copied, modified, or distributed except according to those terms.
8
9//! Errors that can be thrown by Directory.
10
11use crate::error;
12use crate::tuple::PackError;
13use crate::tuple::hca::HcaError;
14use std::io;
15
16/// The enumeration holding all possible errors from a Directory.
17#[derive(Debug)]
18pub enum DirectoryError {
19 /// cannot modify the root directory
20 CannotModifyRootDirectory,
21 /// prefix is already used
22 DirectoryPrefixInUse,
23 /// Directory does not exists
24 DirectoryDoesNotExists,
25 /// missing path.
26 NoPathProvided,
27 /// tried to create an already existing path.
28 DirAlreadyExists,
29 /// missing directory.
30 PathDoesNotExists,
31 /// Parent does not exists
32 ParentDirDoesNotExists,
33 /// the layer is incompatible.
34 IncompatibleLayer,
35 /// the destination directory cannot be a subdirectory of the source directory.
36 BadDestinationDirectory,
37 /// Bad directory version.
38 Version(String),
39 /// cannot specify a prefix unless manual prefixes are enabled
40 PrefixNotAllowed,
41 /// cannot specify a prefix in a partition.
42 CannotPrefixInPartition,
43 /// the root directory cannot be moved
44 CannotMoveRootDirectory,
45 CannotMoveBetweenPartition,
46 /// the destination directory cannot be a subdirectory of the source directory
47 CannotMoveBetweenSubdirectory,
48 /// Prefix is not empty
49 PrefixNotEmpty,
50 /// Thrown when the subpath cannot be computed due to length errors
51 CannotCreateSubpath,
52 /// cannot open subspace in the root of a directory partition
53 CannotOpenDirectoryPartition,
54 /// cannot get key for the root of a directory partition
55 CannotGetKeyDirectoryPartition,
56 /// cannot pack for the root of a directory partition
57 CannotPackDirectoryPartition,
58 /// cannot unpack keys using the root of a directory partition
59 CannotUnpackDirectoryPartition,
60 /// cannot get range for the root of a directory partition
61 CannotRangeDirectoryPartition,
62 IoError(io::Error),
63 FdbError(error::FdbError),
64 HcaError(HcaError),
65 PackError(PackError),
66 Other(String),
67}
68
69impl std::fmt::Display for DirectoryError {
70 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
71 std::fmt::Debug::fmt(self, f)
72 }
73}
74
75impl std::error::Error for DirectoryError {
76 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
77 match self {
78 DirectoryError::IoError(e) => Some(e),
79 DirectoryError::FdbError(e) => Some(e),
80 DirectoryError::HcaError(e) => Some(e),
81 DirectoryError::PackError(e) => Some(e),
82 _ => None,
83 }
84 }
85}
86
87impl From<error::FdbError> for DirectoryError {
88 fn from(err: error::FdbError) -> Self {
89 DirectoryError::FdbError(err)
90 }
91}
92
93impl From<HcaError> for DirectoryError {
94 fn from(err: HcaError) -> Self {
95 DirectoryError::HcaError(err)
96 }
97}
98
99impl From<PackError> for DirectoryError {
100 fn from(err: PackError) -> Self {
101 DirectoryError::PackError(err)
102 }
103}