server: Rename RemoteFileError to StorageError

Already renamed everywhere else.
This commit is contained in:
Zhaofeng Li 2023-01-04 21:05:07 -07:00
parent 49c7cca94b
commit 27836028f4
4 changed files with 30 additions and 30 deletions

View file

@ -269,7 +269,7 @@ async fn upload_path_new(
backend
.upload_file(key, stream.stream())
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
// Confirm that the NAR Hash and Size are correct
// FIXME: errors

View file

@ -42,8 +42,8 @@ pub enum ServerError {
/// Database error: {0}
DatabaseError(AnyError),
/// Remote file error: {0}
RemoteFileError(AnyError),
/// Storage error: {0}
StorageError(AnyError),
/// Manifest serialization error: {0}
ManifestSerializationError(super::nix_manifest::Error),
@ -70,8 +70,8 @@ impl ServerError {
Self::DatabaseError(AnyError::new(error))
}
pub fn remote_file_error(error: impl StdError + Send + Sync + 'static) -> Self {
Self::RemoteFileError(AnyError::new(error))
pub fn storage_error(error: impl StdError + Send + Sync + 'static) -> Self {
Self::StorageError(AnyError::new(error))
}
pub fn request_error(error: impl StdError + Send + Sync + 'static) -> Self {
@ -90,7 +90,7 @@ impl ServerError {
Self::InvalidCompressionType { .. } => "InvalidCompressionType",
Self::AtticError(e) => e.name(),
Self::DatabaseError(_) => "DatabaseError",
Self::RemoteFileError(_) => "RemoteFileError",
Self::StorageError(_) => "StorageError",
Self::ManifestSerializationError(_) => "ManifestSerializationError",
Self::AccessError(_) => "AccessError",
Self::RequestError(_) => "RequestError",
@ -115,7 +115,7 @@ impl ServerError {
Self::AccessError(super::access::Error::NoDiscoveryPermission) => Self::Unauthorized,
Self::DatabaseError(_) => Self::InternalServerError,
Self::RemoteFileError(_) => Self::InternalServerError,
Self::StorageError(_) => Self::InternalServerError,
Self::ManifestSerializationError(_) => Self::InternalServerError,
_ => self,
@ -157,7 +157,7 @@ impl From<super::access::Error> for ServerError {
impl IntoResponse for ServerError {
fn into_response(self) -> Response {
// TODO: Better logging control
if matches!(self, Self::DatabaseError(_) | Self::RemoteFileError(_) | Self::ManifestSerializationError(_) | Self::AtticError(_)) {
if matches!(self, Self::DatabaseError(_) | Self::StorageError(_) | Self::ManifestSerializationError(_) | Self::AtticError(_)) {
tracing::error!("{:?}", self);
}

View file

@ -34,7 +34,7 @@ impl LocalBackend {
pub async fn new(config: LocalStorageConfig) -> ServerResult<Self> {
fs::create_dir_all(&config.path)
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(Self { config })
}
@ -53,11 +53,11 @@ impl StorageBackend for LocalBackend {
) -> ServerResult<RemoteFile> {
let mut file = File::create(self.get_path(&name))
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
io::copy(&mut stream, &mut file)
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(RemoteFile::Local(LocalRemoteFile { name }))
}
@ -65,7 +65,7 @@ impl StorageBackend for LocalBackend {
async fn delete_file(&self, name: String) -> ServerResult<()> {
fs::remove_file(self.get_path(&name))
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(())
}
@ -74,14 +74,14 @@ impl StorageBackend for LocalBackend {
let file = if let RemoteFile::Local(file) = file {
file
} else {
return Err(ServerError::RemoteFileError(anyhow::anyhow!(
return Err(ServerError::StorageError(anyhow::anyhow!(
"Does not understand the remote file reference"
)));
};
fs::remove_file(self.get_path(&file.name))
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(())
}
@ -89,7 +89,7 @@ impl StorageBackend for LocalBackend {
async fn download_file(&self, name: String) -> ServerResult<Download> {
let file = File::open(self.get_path(&name))
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(Download::Stream(Box::new(file)))
}
@ -98,14 +98,14 @@ impl StorageBackend for LocalBackend {
let file = if let RemoteFile::Local(file) = file {
file
} else {
return Err(ServerError::RemoteFileError(anyhow::anyhow!(
return Err(ServerError::StorageError(anyhow::anyhow!(
"Does not understand the remote file reference"
)));
};
let file = File::open(self.get_path(&file.name))
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(Download::Stream(Box::new(file)))
}

View file

@ -99,7 +99,7 @@ impl S3Backend {
}
if let Some(endpoint) = &config.endpoint {
let endpoint = Endpoint::immutable(endpoint).map_err(ServerError::remote_file_error)?;
let endpoint = Endpoint::immutable(endpoint).map_err(ServerError::storage_error)?;
builder = builder.endpoint_resolver(endpoint);
}
@ -113,7 +113,7 @@ impl S3Backend {
let file = if let RemoteFile::S3(file) = file {
file
} else {
return Err(ServerError::RemoteFileError(anyhow::anyhow!(
return Err(ServerError::StorageError(anyhow::anyhow!(
"Does not understand the remote file reference"
)));
};
@ -152,7 +152,7 @@ impl StorageBackend for S3Backend {
.body(first_chunk.into())
.send()
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
tracing::debug!("put_object -> {:#?}", put_object);
@ -170,7 +170,7 @@ impl StorageBackend for S3Backend {
.key(&name)
.send()
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
let upload_id = multipart.upload_id().unwrap();
@ -233,7 +233,7 @@ impl StorageBackend for S3Backend {
.into_iter()
.map(|join_result| join_result.unwrap())
.collect::<std::result::Result<Vec<_>, _>>()
.map_err(ServerError::remote_file_error)?
.map_err(ServerError::storage_error)?
.into_iter()
.enumerate()
.map(|(idx, part)| {
@ -262,7 +262,7 @@ impl StorageBackend for S3Backend {
.multipart_upload(completed_multipart_upload)
.send()
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
tracing::debug!("complete_multipart_upload -> {:#?}", completion);
@ -283,7 +283,7 @@ impl StorageBackend for S3Backend {
.key(&name)
.send()
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
tracing::debug!("delete_file -> {:#?}", deletion);
@ -299,7 +299,7 @@ impl StorageBackend for S3Backend {
.key(&file.key)
.send()
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
tracing::debug!("delete_file -> {:#?}", deletion);
@ -309,7 +309,7 @@ impl StorageBackend for S3Backend {
async fn download_file(&self, name: String) -> ServerResult<Download> {
// FIXME: Configurable expiration
let presign_config = PresigningConfig::expires_in(Duration::from_secs(10))
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
let presigned = self
.client
@ -318,7 +318,7 @@ impl StorageBackend for S3Backend {
.key(&name)
.presigned(presign_config)
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(Download::Redirect(presigned.uri().to_string()))
}
@ -327,7 +327,7 @@ impl StorageBackend for S3Backend {
let (client, file) = self.get_client_from_db_ref(file).await?;
let presign_config = PresigningConfig::expires_in(Duration::from_secs(600))
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
let presigned = client
.get_object()
@ -335,7 +335,7 @@ impl StorageBackend for S3Backend {
.key(&file.key)
.presigned(presign_config)
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
Ok(Download::Redirect(presigned.uri().to_string()))
}
@ -359,7 +359,7 @@ async fn read_chunk_async<S: AsyncRead + Unpin + Send>(stream: &mut S) -> Server
let read = stream
.read(buf)
.await
.map_err(ServerError::remote_file_error)?;
.map_err(ServerError::storage_error)?;
if read == 0 {
break;