Skip to content

Commit

Permalink
more error fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiepine committed Dec 24, 2024
1 parent aafbabc commit 953000c
Show file tree
Hide file tree
Showing 54 changed files with 558 additions and 460 deletions.
33 changes: 29 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions core/crates/api/src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ use crate::{
location::{get_location_path_from_location_id, LocationError},
object::fs::{
error::FileSystemJobsError, find_available_filename_for_duplicate,
old_copy::OldFileCopierJobInit,
old_erase::OldFileEraserJobInit,
old_copy::OldFileCopierJobInit, old_erase::OldFileEraserJobInit,
},
old_job::OldJob,
};

use sd_core_file_helper::{FilePathError, IsolatedFilePathData};
use sd_core_file_helper::IsolatedFilePathData;
use sd_core_heavy_lifting::{
media_processor::{exif_media_data, ffmpeg_media_data},
JobEnqueuer,
Expand All @@ -21,19 +20,20 @@ use sd_core_prisma_helpers::{
file_path_to_isolate, file_path_to_isolate_with_id, object_with_file_paths,
object_with_media_data,
};
use sd_core_shared_errors::file_helper::Error as FileHelperError;

use sd_file_ext::kind::ObjectKind;
use sd_file_actions::deleter::{MoveToTrashJob, RemoveJob};
use sd_file_ext::kind::ObjectKind;
use sd_images::ConvertibleExtension;
use sd_media_metadata::{ExifMetadata, FFmpegMetadata};
use sd_prisma::{
prisma::{file_path, location, object},
prisma_sync,
};

use sd_utils::{error::FileIOError, msgpack};
use sd_sync::{sync_db_entry, sync_db_nullable_entry, sync_entry, OperationFactory};
use sd_utils::{db::maybe_missing, error::FileIOError};
use sd_utils::{error::FileIOError, msgpack};

use std::{
ffi::OsString,
Expand Down
203 changes: 0 additions & 203 deletions core/crates/cloud-services/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,204 +1 @@
use sd_cloud_schema::{
cloud_p2p,
sync::{self, groups},
Request, Response,
};
use sd_utils::error::FileIOError;

use std::{io, net::AddrParseError};

use quic_rpc::{
pattern::{bidi_streaming, rpc, server_streaming},
transport::{mapped::MappedConnector, quinn::QuinnConnector},
};

#[derive(thiserror::Error, Debug)]
pub enum Error {
// Setup errors
#[error("Couldn't parse Cloud Services API address URL: {0}")]
InvalidUrl(reqwest::Error),
#[error("Failed to parse Cloud Services API address URL")]
FailedToParseRelayUrl,
#[error("Failed to initialize http client: {0}")]
HttpClientInit(reqwest::Error),
#[error("Failed to request Cloud Services API address from Auth Server route: {0}")]
FailedToRequestApiAddress(reqwest_middleware::Error),
#[error("Auth Server's Cloud Services API address route returned an error: {0}")]
AuthServerError(reqwest::Error),
#[error(
"Failed to extract response body from Auth Server's Cloud Services API address route: {0}"
)]
FailedToExtractApiAddress(reqwest::Error),
#[error("Failed to parse auth server's Cloud Services API address: {0}")]
FailedToParseApiAddress(#[from] AddrParseError),
#[error("Failed to create endpoint: {0}")]
FailedToCreateEndpoint(io::Error),

// Token refresher errors
#[error("Invalid token format, missing claims")]
MissingClaims,
#[error("Failed to decode access token data: {0}")]
DecodeAccessTokenData(#[from] base64::DecodeError),
#[error("Failed to deserialize access token json data: {0}")]
DeserializeAccessTokenData(#[from] serde_json::Error),
#[error("Token expired")]
TokenExpired,
#[error("Failed to request refresh token: {0}")]
RefreshTokenRequest(reqwest_middleware::Error),
#[error("Missing tokens on refresh response")]
MissingTokensOnRefreshResponse,
#[error("Failed to parse token header value to string: {0}")]
FailedToParseTokenHeaderValueToString(#[from] reqwest::header::ToStrError),

// Key Manager errors
#[error("Failed to handle File on KeyManager: {0}")]
FileIO(#[from] FileIOError),
#[error("Failed to handle key store serialization: {0}")]
KeyStoreSerialization(rmp_serde::encode::Error),
#[error("Failed to handle key store deserialization: {0}")]
KeyStoreDeserialization(rmp_serde::decode::Error),
#[error("Key store encryption related error: {{context: \"{context}\", source: {source}}}")]
KeyStoreCrypto {
#[source]
source: sd_crypto::Error,
context: &'static str,
},
#[error("Key manager not initialized")]
KeyManagerNotInitialized,

// Cloud P2P errors
#[error("Failed to create Cloud P2P endpoint: {0}")]
CreateCloudP2PEndpoint(anyhow::Error),
#[error("Failed to connect to Cloud P2P node: {0}")]
ConnectToCloudP2PNode(anyhow::Error),
#[error("Communication error with Cloud P2P node: {0}")]
CloudP2PRpcCommunication(
#[from] rpc::Error<QuinnConnector<cloud_p2p::Response, cloud_p2p::Request>>,
),
#[error("Cloud P2P not initialized")]
CloudP2PNotInitialized,
#[error("Failed to initialize LocalSwarmDiscovery: {0}")]
LocalSwarmDiscoveryInit(anyhow::Error),
#[error("Failed to initialize DhtDiscovery: {0}")]
DhtDiscoveryInit(anyhow::Error),

// Communication errors
#[error("Failed to communicate with RPC backend: {0}")]
RpcCommunication(#[from] rpc::Error<QuinnConnector<Response, Request>>),
#[error("Failed to communicate with RPC sync backend: {0}")]
RpcSyncCommunication(
#[from]
rpc::Error<
MappedConnector<sync::Response, sync::Request, QuinnConnector<Response, Request>>,
>,
),
#[error("Failed to communicate with Server Streaming RPC backend: {0}")]
ServerStreamCommunication(#[from] server_streaming::Error<QuinnConnector<Response, Request>>),
#[error("Failed to communicate with Server Streaming RPC sync backend: {0}")]
ServerStreamSyncCommunication(
#[from]
server_streaming::Error<
MappedConnector<sync::Response, sync::Request, QuinnConnector<Response, Request>>,
>,
),
#[error("Failed to receive next response from Server Streaming RPC backend: {0}")]
ServerStreamRecv(#[from] server_streaming::ItemError<QuinnConnector<Response, Request>>),
#[error("Failed to receive next response from Server Streaming RPC sync backend: {0}")]
ServerStreamSyncRecv(
#[from]
server_streaming::ItemError<
MappedConnector<sync::Response, sync::Request, QuinnConnector<Response, Request>>,
>,
),
#[error("Failed to communicate with Bidi Streaming RPC backend: {0}")]
BidiStreamCommunication(#[from] bidi_streaming::Error<QuinnConnector<Response, Request>>),
#[error("Failed to communicate with Bidi Streaming RPC sync backend: {0}")]
BidiStreamSyncCommunication(
#[from]
bidi_streaming::Error<
MappedConnector<sync::Response, sync::Request, QuinnConnector<Response, Request>>,
>,
),
#[error("Failed to receive next response from Bidi Streaming RPC backend: {0}")]
BidiStreamRecv(#[from] bidi_streaming::ItemError<QuinnConnector<Response, Request>>),
#[error("Error from backend: {0}")]
Backend(#[from] sd_cloud_schema::Error),
#[error("Failed to get access token from refresher: {0}")]
GetToken(#[from] GetTokenError),
#[error("Unexpected empty response from backend, context: {0}")]
EmptyResponse(&'static str),
#[error("Unexpected response from backend, context: {0}")]
UnexpectedResponse(&'static str),

// Sync error
#[error("Sync error: {0}")]
Sync(#[from] sd_core_library_sync::Error),
#[error("Tried to sync messages with a group without having needed key")]
MissingSyncGroupKey(groups::PubId),
#[error("Failed to encrypt sync messages: {0}")]
Encrypt(sd_crypto::Error),
#[error("Failed to decrypt sync messages: {0}")]
Decrypt(sd_crypto::Error),
#[error("Failed to upload sync messages: {0}")]
UploadSyncMessages(reqwest_middleware::Error),
#[error("Failed to download sync messages: {0}")]
DownloadSyncMessages(reqwest_middleware::Error),
#[error("Received an error response from uploading sync messages: {0}")]
ErrorResponseUploadSyncMessages(reqwest::Error),
#[error("Received an error response from downloading sync messages: {0}")]
ErrorResponseDownloadSyncMessages(reqwest::Error),
#[error(
"Received an error response from downloading sync messages while reading its bytes: {0}"
)]
ErrorResponseDownloadReadBytesSyncMessages(reqwest::Error),
#[error("Critical error while uploading sync messages")]
CriticalErrorWhileUploadingSyncMessages,
#[error("Failed to send End update to push sync messages")]
EndUpdatePushSyncMessages(io::Error),
#[error("Unexpected end of stream while encrypting sync messages")]
UnexpectedEndOfStream,
#[error("Failed to create directory to store timestamp keeper files")]
FailedToCreateTimestampKeepersDirectory(io::Error),
#[error("Failed to read last timestamp keeper for pulling sync messages: {0}")]
FailedToReadLastTimestampKeeper(io::Error),
#[error("Failed to handle last timestamp keeper serialization: {0}")]
LastTimestampKeeperSerialization(rmp_serde::encode::Error),
#[error("Failed to handle last timestamp keeper deserialization: {0}")]
LastTimestampKeeperDeserialization(rmp_serde::decode::Error),
#[error("Failed to write last timestamp keeper for pulling sync messages: {0}")]
FailedToWriteLastTimestampKeeper(io::Error),
#[error("Sync messages download and decrypt task panicked")]
SyncMessagesDownloadAndDecryptTaskPanicked,
#[error("Serialization failure to push sync messages: {0}")]
SerializationFailureToPushSyncMessages(rmp_serde::encode::Error),
#[error("Deserialization failure to pull sync messages: {0}")]
DeserializationFailureToPullSyncMessages(rmp_serde::decode::Error),
#[error("Read nonce stream decryption: {0}")]
ReadNonceStreamDecryption(io::Error),
#[error("Incomplete download bytes sync messages")]
IncompleteDownloadBytesSyncMessages,

// Temporary errors
#[error("Device missing secret key for decrypting sync messages")]
MissingKeyHash,
}

#[derive(thiserror::Error, Debug)]
pub enum GetTokenError {
#[error("Token refresher not initialized")]
RefresherNotInitialized,
#[error("Token refresher failed to refresh and need to be initialized again")]
FailedToRefresh,
}

impl From<Error> for rspc::Error {
fn from(e: Error) -> Self {
Self::with_cause(rspc::ErrorCode::InternalServerError, e.to_string(), e)
}
}

impl From<GetTokenError> for rspc::Error {
fn from(e: GetTokenError) -> Self {
Self::with_cause(rspc::ErrorCode::InternalServerError, e.to_string(), e)
}
}
1 change: 1 addition & 0 deletions core/crates/file-helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ rust-version.workspace = true
# Inner Core Sub-crates
sd-core-library-sync = { path = "../library-sync" }
sd-core-prisma-helpers = { path = "../prisma-helpers" }
sd-core-shared-errors = { path = "../shared-errors" }

# Spacedrive Sub-crates
sd-prisma = { path = "../../../crates/prisma" }
Expand Down
2 changes: 1 addition & 1 deletion core/crates/file-helper/src/isolated_file_path_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{
use regex::RegexSet;
use serde::{Deserialize, Serialize};

use super::FilePathError;
use sd_core_shared_errors::file_helper::Error as FilePathError;

static FORBIDDEN_FILE_NAMES: OnceLock<RegexSet> = OnceLock::new();

Expand Down
Loading

0 comments on commit 953000c

Please sign in to comment.