Unverified Commit 30f5c363 authored by Nugine's avatar Nugine
Browse files

codegen: error: custom

parent 4a1f7dfd
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -111,8 +111,11 @@ pub fn codegen(model: &smithy::Model, g: &mut Codegen) {
        err.status.push(status);
    }

    g.ln("use hyper::StatusCode;");
    g.lf();
    g.lines([
        "use bytestring::ByteString;", //
        "use hyper::StatusCode;",      //
        "",                            //
    ]);

    g.ln("#[derive(Debug, Clone, PartialEq, Eq)]");
    g.ln("#[non_exhaustive]");
@@ -149,7 +152,7 @@ pub fn codegen(model: &smithy::Model, g: &mut Codegen) {
        g.ln(f!("{},", err.code));
        g.lf();
    }
    g.ln("Unknown(Box<str>),");
    g.ln("Custom(ByteString),");
    g.ln("}");
    g.lf();

@@ -163,7 +166,7 @@ pub fn codegen(model: &smithy::Model, g: &mut Codegen) {
        for err in errors.values() {
            g.ln(f!("Self::{} => \"{}\",", err.code, err.code));
        }
        g.ln("Self::Unknown(s) => s,");
        g.ln("Self::Custom(s) => s,");
        g.ln("}");

        g.ln("}");
@@ -178,7 +181,7 @@ pub fn codegen(model: &smithy::Model, g: &mut Codegen) {
        for err in errors.values() {
            g.ln(f!("b\"{}\" => Some(Self::{}),", err.code, err.code));
        }
        g.ln("_ => std::str::from_utf8(s).ok().map(|s| Self::Unknown(s.into()))");
        g.ln("_ => std::str::from_utf8(s).ok().map(|s| Self::Custom(s.into()))");
        g.ln("}");

        g.ln("}");
@@ -220,7 +223,7 @@ pub fn codegen(model: &smithy::Model, g: &mut Codegen) {
            }
            g.ln(f!("Self::{} => None,", err.code));
        }
        g.ln("Self::Unknown(_) => None,");
        g.ln("Self::Custom(_) => None,");
        g.ln("}");

        g.ln("}");
+1 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ aws-smithy-http = { version = "0.54.1", optional = true }
aws-smithy-types-convert = { version = "0.54.1", optional = true, features = ["convert-time"] }
base64-simd = "0.8.0"
bytes = "1.3.0"
bytestring = "1.2.0"
chrono = { version = "0.4.23", default-features = false }
futures = { version = "0.3.25", default-features = false, features = ["std"] }
hex-simd = "0.8.0"
+5 −4
Original line number Diff line number Diff line
use bytestring::ByteString;
use hyper::StatusCode;

#[derive(Debug, Clone, PartialEq, Eq)]
@@ -486,7 +487,7 @@ pub enum S3ErrorCode {
    ///
    UserKeyMustBeSpecified,

    Unknown(Box<str>),
    Custom(ByteString),
}

impl S3ErrorCode {
@@ -573,7 +574,7 @@ impl S3ErrorCode {
            Self::UnexpectedContent => "UnexpectedContent",
            Self::UnresolvableGrantByEmailAddress => "UnresolvableGrantByEmailAddress",
            Self::UserKeyMustBeSpecified => "UserKeyMustBeSpecified",
            Self::Unknown(s) => s,
            Self::Custom(s) => s,
        }
    }

@@ -660,7 +661,7 @@ impl S3ErrorCode {
            b"UnexpectedContent" => Some(Self::UnexpectedContent),
            b"UnresolvableGrantByEmailAddress" => Some(Self::UnresolvableGrantByEmailAddress),
            b"UserKeyMustBeSpecified" => Some(Self::UserKeyMustBeSpecified),
            _ => std::str::from_utf8(s).ok().map(|s| Self::Unknown(s.into())),
            _ => std::str::from_utf8(s).ok().map(|s| Self::Custom(s.into())),
        }
    }

@@ -747,7 +748,7 @@ impl S3ErrorCode {
            Self::UnexpectedContent => Some(StatusCode::BAD_REQUEST),
            Self::UnresolvableGrantByEmailAddress => Some(StatusCode::BAD_REQUEST),
            Self::UserKeyMustBeSpecified => Some(StatusCode::BAD_REQUEST),
            Self::Unknown(_) => None,
            Self::Custom(_) => None,
        }
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ use std::mem;
use std::ops::Not;

use bytes::Bytes;
use bytestring::ByteString;
use hyper::Method;
use hyper::StatusCode;
use mime::Mime;
@@ -98,7 +99,7 @@ fn extract_amz_content_sha256<'a>(hs: &'_ OrderedHeaders<'a>) -> S3Result<Option
    match AmzContentSha256::parse(val) {
        Ok(x) => Ok(Some(x)),
        Err(e) => {
            let mut err: S3Error = S3ErrorCode::Unknown("XAmzContentSHA256Mismatch".into()).into();
            let mut err: S3Error = S3ErrorCode::Custom(ByteString::from_static("XAmzContentSHA256Mismatch")).into();
            err.set_message("invalid header: x-amz-content-sha256");
            err.set_source(Box::new(e));
            Err(err)