Skip to content

Commit

Permalink
object_store/lib: Migrate from snafu to thiserror
Browse files Browse the repository at this point in the history
  • Loading branch information
Turbo87 committed Nov 3, 2024
1 parent fc2f78b commit 44ef195
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions object_store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,6 @@ use async_trait::async_trait;
use bytes::Bytes;
use chrono::{DateTime, Utc};
use futures::{stream::BoxStream, StreamExt, TryStreamExt};
use snafu::Snafu;
use std::fmt::{Debug, Formatter};
#[cfg(not(target_arch = "wasm32"))]
use std::io::{Read, Seek, SeekFrom};
Expand Down Expand Up @@ -1224,11 +1223,11 @@ pub struct PutResult {
pub type Result<T, E = Error> = std::result::Result<T, E>;

/// A specialized `Error` for object store-related errors
#[derive(Debug, Snafu)]
#[derive(Debug, thiserror::Error)]
#[non_exhaustive]
pub enum Error {
/// A fallback error type when no variant matches
#[snafu(display("Generic {} error: {}", store, source))]
#[error("Generic {} error: {}", store, source)]
Generic {
/// The store this error originated from
store: &'static str,
Expand All @@ -1237,7 +1236,7 @@ pub enum Error {
},

/// Error when the object is not found at given location
#[snafu(display("Object at location {} not found: {}", path, source))]
#[error("Object at location {} not found: {}", path, source)]
NotFound {
/// The path to file
path: String,
Expand All @@ -1246,31 +1245,30 @@ pub enum Error {
},

/// Error for invalid path
#[snafu(
display("Encountered object with invalid path: {}", source),
context(false)
)]
#[error("Encountered object with invalid path: {}", source)]
InvalidPath {
/// The wrapped error
#[from]
source: path::Error,
},

/// Error when `tokio::spawn` failed
#[snafu(display("Error joining spawned task: {}", source), context(false))]
#[error("Error joining spawned task: {}", source)]
JoinError {
/// The wrapped error
#[from]
source: tokio::task::JoinError,
},

/// Error when the attempted operation is not supported
#[snafu(display("Operation not supported: {}", source))]
#[error("Operation not supported: {}", source)]
NotSupported {
/// The wrapped error
source: Box<dyn std::error::Error + Send + Sync + 'static>,
},

/// Error when the object already exists
#[snafu(display("Object at location {} already exists: {}", path, source))]
#[error("Object at location {} already exists: {}", path, source)]
AlreadyExists {
/// The path to the
path: String,
Expand All @@ -1279,7 +1277,7 @@ pub enum Error {
},

/// Error when the required conditions failed for the operation
#[snafu(display("Request precondition failure for path {}: {}", path, source))]
#[error("Request precondition failure for path {}: {}", path, source)]
Precondition {
/// The path to the file
path: String,
Expand All @@ -1288,7 +1286,7 @@ pub enum Error {
},

/// Error when the object at the location isn't modified
#[snafu(display("Object at location {} not modified: {}", path, source))]
#[error("Object at location {} not modified: {}", path, source)]
NotModified {
/// The path to the file
path: String,
Expand All @@ -1297,16 +1295,16 @@ pub enum Error {
},

/// Error when an operation is not implemented
#[snafu(display("Operation not yet implemented."))]
#[error("Operation not yet implemented.")]
NotImplemented,

/// Error when the used credentials don't have enough permission
/// to perform the requested operation
#[snafu(display(
#[error(
"The operation lacked the necessary privileges to complete for path {}: {}",
path,
source
))]
)]
PermissionDenied {
/// The path to the file
path: String,
Expand All @@ -1315,11 +1313,11 @@ pub enum Error {
},

/// Error when the used credentials lack valid authentication
#[snafu(display(
#[error(
"The operation lacked valid authentication credentials for path {}: {}",
path,
source
))]
)]
Unauthenticated {
/// The path to the file
path: String,
Expand All @@ -1328,7 +1326,7 @@ pub enum Error {
},

/// Error when a configuration key is invalid for the store used
#[snafu(display("Configuration key: '{}' is not valid for store '{}'.", key, store))]
#[error("Configuration key: '{}' is not valid for store '{}'.", key, store)]
UnknownConfigurationKey {
/// The object store used
store: &'static str,
Expand Down

0 comments on commit 44ef195

Please sign in to comment.