cloud_filter/
error.rs

1use windows::Win32::Foundation::{self, NTSTATUS};
2
3/// [SyncFilter][crate::filter::SyncFilter] trait callback result type.
4pub type CResult<T> = std::result::Result<T, CloudErrorKind>;
5
6/// Predefined error types provided by the operating system.
7#[derive(Debug, Clone, Copy)]
8pub enum CloudErrorKind {
9    /// Access to the cloud file is denied.
10    AccessDenied,
11    /// The cloud sync root is already connected with another cloud sync provider.
12    AlreadyConnected,
13    /// The cloud sync provider failed user authentication.
14    AuthenticationFailed,
15    /// The operation is reserved for a connected cloud sync provider.
16    ConnectedProviderOnly,
17    /// Dehydration of the cloud file is disallowed by the cloud sync provider.
18    DehydrationDisallowed,
19    /// The cloud operation cannot be performed on a file with incompatible hardlinks.
20    IncompatibleHardlinks,
21    /// The cloud sync provider failed to perform the operation due to low system resources.
22    InsufficientResources,
23    /// The cloud operation is invalid.
24    InvalidRequest,
25    /// The operation cannot be performed on cloud files in use.
26    InUse,
27    /// The cloud file metadata is corrupt and unreadable.
28    MetadataCorrupt,
29    /// The cloud file metadata is too large.
30    MetadataTooLarge,
31    /// The cloud sync provider failed to perform the operation due to network being unavailable.
32    NetworkUnavailable,
33    /// The file is not in sync with the cloud.
34    NotInSync,
35    /// The operation is not supported by the cloud sync provider.
36    NotSupported,
37    /// The operation is only supported on files under a cloud sync root.
38    NotUnderSyncRoot,
39    /// The operation cannot be performed on pinned cloud files.
40    Pinned,
41    /// The cloud file property is possibly corrupt. The on-disk checksum does not match the
42    /// computed checksum.
43    PropertyBlobChecksumMismatch,
44    /// The cloud file property is too large.
45    PropertyBlobTooLarge,
46    /// The cloud file's property store is corrupt.
47    PropertyCorrupt,
48    /// The operation failed due to a conflicting cloud file property lock.
49    PropertyLockConflict,
50    /// The version of the cloud file property store is not supported.
51    PropertyVersionNotSupported,
52    /// The cloud file provider is not running.
53    ProviderNotRunning,
54    /// The cloud file provider exited unexpectedly.
55    ProviderTerminated,
56    /// The cloud operation is not supported on a read-only volume.
57    ReadOnlyVolume,
58    /// The cloud operation was aborted.
59    RequestAborted,
60    /// The cloud operation was canceled by user.
61    RequestCancelled,
62    /// The cloud operation was not completed before the time-out period expired.
63    RequestTimeout,
64    /// The cloud sync root metadata is corrupted.
65    SyncRootMetadataCorrupt,
66    /// The maximum number of cloud file properties has been reached.
67    TooManyPropertyBlobs,
68    /// The cloud operation was unsuccessful.
69    Unsuccessful,
70    /// The cloud sync provider failed to validate the downloaded data.
71    ValidationFailed,
72}
73
74impl From<CloudErrorKind> for NTSTATUS {
75    fn from(error: CloudErrorKind) -> Self {
76        match error {
77            CloudErrorKind::AccessDenied => Foundation::STATUS_CLOUD_FILE_ACCESS_DENIED,
78            CloudErrorKind::AlreadyConnected => Foundation::STATUS_CLOUD_FILE_ALREADY_CONNECTED,
79            CloudErrorKind::AuthenticationFailed => {
80                Foundation::STATUS_CLOUD_FILE_AUTHENTICATION_FAILED
81            }
82            CloudErrorKind::ConnectedProviderOnly => {
83                Foundation::STATUS_CLOUD_FILE_CONNECTED_PROVIDER_ONLY
84            }
85            CloudErrorKind::DehydrationDisallowed => {
86                Foundation::STATUS_CLOUD_FILE_DEHYDRATION_DISALLOWED
87            }
88            CloudErrorKind::IncompatibleHardlinks => {
89                Foundation::STATUS_CLOUD_FILE_INCOMPATIBLE_HARDLINKS
90            }
91            CloudErrorKind::InsufficientResources => {
92                Foundation::STATUS_CLOUD_FILE_INSUFFICIENT_RESOURCES
93            }
94            CloudErrorKind::InvalidRequest => Foundation::STATUS_CLOUD_FILE_INVALID_REQUEST,
95            CloudErrorKind::InUse => Foundation::STATUS_CLOUD_FILE_IN_USE,
96            CloudErrorKind::MetadataCorrupt => Foundation::STATUS_CLOUD_FILE_METADATA_CORRUPT,
97            CloudErrorKind::MetadataTooLarge => Foundation::STATUS_CLOUD_FILE_METADATA_TOO_LARGE,
98            CloudErrorKind::NetworkUnavailable => Foundation::STATUS_CLOUD_FILE_NETWORK_UNAVAILABLE,
99            CloudErrorKind::NotInSync => Foundation::STATUS_CLOUD_FILE_NOT_IN_SYNC,
100            CloudErrorKind::NotSupported => Foundation::STATUS_CLOUD_FILE_NOT_SUPPORTED,
101            CloudErrorKind::NotUnderSyncRoot => Foundation::STATUS_CLOUD_FILE_NOT_UNDER_SYNC_ROOT,
102            CloudErrorKind::Pinned => Foundation::STATUS_CLOUD_FILE_PINNED,
103            CloudErrorKind::PropertyBlobChecksumMismatch => {
104                Foundation::STATUS_CLOUD_FILE_PROPERTY_BLOB_CHECKSUM_MISMATCH
105            }
106            CloudErrorKind::PropertyBlobTooLarge => {
107                Foundation::STATUS_CLOUD_FILE_PROPERTY_BLOB_TOO_LARGE
108            }
109            CloudErrorKind::PropertyCorrupt => Foundation::STATUS_CLOUD_FILE_PROPERTY_CORRUPT,
110            CloudErrorKind::PropertyLockConflict => {
111                Foundation::STATUS_CLOUD_FILE_PROPERTY_LOCK_CONFLICT
112            }
113            CloudErrorKind::PropertyVersionNotSupported => {
114                Foundation::STATUS_CLOUD_FILE_PROPERTY_VERSION_NOT_SUPPORTED
115            }
116            CloudErrorKind::ProviderNotRunning => {
117                Foundation::STATUS_CLOUD_FILE_PROVIDER_NOT_RUNNING
118            }
119            CloudErrorKind::ProviderTerminated => Foundation::STATUS_CLOUD_FILE_PROVIDER_TERMINATED,
120            CloudErrorKind::ReadOnlyVolume => Foundation::STATUS_CLOUD_FILE_READ_ONLY_VOLUME,
121            CloudErrorKind::RequestAborted => Foundation::STATUS_CLOUD_FILE_REQUEST_ABORTED,
122            CloudErrorKind::RequestCancelled => Foundation::STATUS_CLOUD_FILE_REQUEST_CANCELED,
123            CloudErrorKind::RequestTimeout => Foundation::STATUS_CLOUD_FILE_REQUEST_TIMEOUT,
124            CloudErrorKind::SyncRootMetadataCorrupt => {
125                Foundation::STATUS_CLOUD_FILE_SYNC_ROOT_METADATA_CORRUPT
126            }
127            CloudErrorKind::TooManyPropertyBlobs => {
128                Foundation::STATUS_CLOUD_FILE_TOO_MANY_PROPERTY_BLOBS
129            }
130            CloudErrorKind::Unsuccessful => Foundation::STATUS_CLOUD_FILE_UNSUCCESSFUL,
131            CloudErrorKind::ValidationFailed => Foundation::STATUS_CLOUD_FILE_VALIDATION_FAILED,
132        }
133    }
134}