Unverified Commit a71189ad authored by Nugine's avatar Nugine
Browse files

s3s: error: StdError

parent 1e124784
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
use s3s::S3Error;
use s3s::S3ErrorCode;
use s3s::StdError;

use std::panic::Location;

@@ -7,7 +8,7 @@ use tracing::error;

#[derive(Debug)]
pub struct Error {
    source: Box<dyn std::error::Error + Send + Sync + 'static>,
    source: StdError,
}

pub type Result<T = (), E = Error> = std::result::Result<T, E>;
@@ -15,7 +16,7 @@ pub type Result<T = (), E = Error> = std::result::Result<T, E>;
impl Error {
    #[must_use]
    #[track_caller]
    pub fn new(source: Box<dyn std::error::Error + Send + Sync + 'static>) -> Self {
    pub fn new(source: StdError) -> Self {
        log(&*source);
        Self { source }
    }
+3 −1
Original line number Diff line number Diff line
use crate::error::*;

use s3s::StdError;

use tokio::io::AsyncWrite;
use tokio::io::AsyncWriteExt;

@@ -10,7 +12,7 @@ use transform_stream::AsyncTryStream;

pub async fn copy_bytes<S, W>(mut stream: S, writer: &mut W) -> Result<u64>
where
    S: Stream<Item = Result<Bytes, Box<dyn std::error::Error + Send + Sync + 'static>>> + Unpin,
    S: Stream<Item = Result<Bytes, StdError>> + Unpin,
    W: AsyncWrite + Unpin,
{
    let mut nwritten: u64 = 0;
+5 −3
Original line number Diff line number Diff line
@@ -11,6 +11,8 @@ use std::str::FromStr;

use hyper::StatusCode;

pub type StdError = Box<dyn std::error::Error + Send + Sync + 'static>;

pub type S3Result<T = (), E = S3Error> = std::result::Result<T, E>;

#[derive(Debug, thiserror::Error)]
@@ -23,7 +25,7 @@ struct Inner {
    // resource: Option<String>,
    request_id: Option<String>,
    status_code: Option<StatusCode>,
    source: Option<Box<dyn std::error::Error + Send + Sync + 'static>>,
    source: Option<StdError>,
}

impl S3Error {
@@ -47,7 +49,7 @@ impl S3Error {
    }

    #[must_use]
    pub fn with_source(code: S3ErrorCode, source: Box<dyn std::error::Error + Send + Sync + 'static>) -> Self {
    pub fn with_source(code: S3ErrorCode, source: StdError) -> Self {
        let mut this = Self::new(code);
        this.0.source = Some(source);
        this
@@ -65,7 +67,7 @@ impl S3Error {
        self.0.request_id = Some(val.into());
    }

    pub fn set_source(&mut self, val: Box<dyn std::error::Error + Send + Sync + 'static>) {
    pub fn set_source(&mut self, val: StdError) {
        self.0.source = Some(val);
    }