---
source: apollo-errors/crates/apollo-errors-derive/src/tests.rs
expression: pretty_print(output)
---
#[automatically_derived]
impl ::std::fmt::Display for ErrorWithUrl {
    fn fmt(
        &self,
        __apollo_formatter: &mut ::std::fmt::Formatter<'_>,
    ) -> ::std::fmt::Result {
        match self {
            Self::ConnectionFailed => {
                write!(__apollo_formatter, "Database connection failed")
            }
        }
    }
}
#[automatically_derived]
impl ::std::error::Error for ErrorWithUrl {
    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
        match self {
            Self::ConnectionFailed => ::std::option::Option::None,
        }
    }
}
#[automatically_derived]
impl ::apollo_errors::Error for ErrorWithUrl {
    fn to_json(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::result::Result<
        ::apollo_errors::private::serde_json::Value,
        ::apollo_errors::private::serde_json::Error,
    > {
        match self {
            Self::ConnectionFailed => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => {
                        "db::connection_failed"
                    }
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "DB_CONNECTION_FAILED"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "dbConnectionFailed",
                    ::apollo_errors::private::CodeCase::PascalCase => {
                        "DbConnectionFailed"
                    }
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "db-connection-failed"
                    }
                };
                let __apollo_message = ::std::string::ToString::to_string(self);
                ::std::result::Result::Ok(
                    ::apollo_errors::private::serde_json::json!(
                        { "error" : __apollo_code, "message" : __apollo_message }
                    ),
                )
            }
        }
    }
    fn to_html(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::string::String {
        match self {
            Self::ConnectionFailed => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => {
                        "db::connection_failed"
                    }
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "DB_CONNECTION_FAILED"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "dbConnectionFailed",
                    ::apollo_errors::private::CodeCase::PascalCase => {
                        "DbConnectionFailed"
                    }
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "db-connection-failed"
                    }
                };
                let __apollo_message = ::std::string::ToString::to_string(self);
                let __apollo_help_html = ::apollo_errors::private::diagnostic_help(self)
                    .map(|h| {
                        format!(
                            "<p class=\"error-help\">{}</p>",
                            ::apollo_errors::private::HtmlEscaped(h)
                        )
                    })
                    .unwrap_or_default();
                let __apollo_extensions_html = ::std::string::String::new();
                format!(
                    "<div class=\"error\">\n<h3 class=\"error-code\">{}</h3>\n<p class=\"error-message\">{}</p>\n{}{}\n</div>",
                    ::apollo_errors::private::HtmlEscaped(__apollo_code),
                    ::apollo_errors::private::HtmlEscaped(& __apollo_message),
                    __apollo_help_html, __apollo_extensions_html
                )
            }
        }
    }
    fn to_graphql(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::result::Result<
        ::apollo_errors::private::serde_json::Value,
        ::apollo_errors::private::serde_json::Error,
    > {
        match self {
            Self::ConnectionFailed => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => {
                        "db::connection_failed"
                    }
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "DB_CONNECTION_FAILED"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "dbConnectionFailed",
                    ::apollo_errors::private::CodeCase::PascalCase => {
                        "DbConnectionFailed"
                    }
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "db-connection-failed"
                    }
                };
                let __apollo_message = ::std::string::ToString::to_string(self);
                ::std::result::Result::Ok(
                    ::apollo_errors::private::serde_json::json!(
                        { "message" : __apollo_message, "extensions" : { "code" :
                        __apollo_code } }
                    ),
                )
            }
        }
    }
    fn to_text(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::string::String {
        match self {
            Self::ConnectionFailed => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => {
                        "db::connection_failed"
                    }
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "DB_CONNECTION_FAILED"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "dbConnectionFailed",
                    ::apollo_errors::private::CodeCase::PascalCase => {
                        "DbConnectionFailed"
                    }
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "db-connection-failed"
                    }
                };
                let __apollo_message = ::std::string::ToString::to_string(self);
                format!("[{__apollo_code}] {__apollo_message}")
            }
        }
    }
    fn to_jsonrpc(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::result::Result<
        ::apollo_errors::private::serde_json::Value,
        ::apollo_errors::private::serde_json::Error,
    > {
        let __apollo_message = ::std::string::ToString::to_string(self);
        match self {
            Self::ConnectionFailed => {
                let __apollo_diagnostic_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => {
                        "db::connection_failed"
                    }
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "DB_CONNECTION_FAILED"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "dbConnectionFailed",
                    ::apollo_errors::private::CodeCase::PascalCase => {
                        "DbConnectionFailed"
                    }
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "db-connection-failed"
                    }
                };
                let mut __apollo_data = ::apollo_errors::private::serde_json::json!(
                    { "diagnostic_code" : __apollo_diagnostic_code }
                );
                if let ::apollo_errors::private::serde_json::Value::Object(
                    ref mut __apollo_map,
                ) = __apollo_data {}
                ::std::result::Result::Ok(
                    ::apollo_errors::private::serde_json::json!(
                        { "code" : - 32000i32, "message" : __apollo_message, "data" :
                        __apollo_data }
                    ),
                )
            }
        }
    }
    fn http_status(&self) -> ::apollo_errors::http::StatusCode {
        match self {
            Self::ConnectionFailed => ::http::StatusCode::INTERNAL_SERVER_ERROR,
        }
    }
    fn http_headers(
        &self,
    ) -> Vec<(::apollo_errors::http::HeaderName, ::apollo_errors::http::HeaderValue)> {
        match self {
            Self::ConnectionFailed => Vec::new(),
        }
    }
}
static _APOLLO_ERROR_ERRORWITHURL_FIELDS_CONNECTIONFAILED: &[::apollo_errors::private::FieldMetadata] = &[];
static _APOLLO_ERROR_ERRORWITHURL_VARIANTS: &[::apollo_errors::private::VariantMetadata] = &[
    ::apollo_errors::private::VariantMetadata::Regular(::apollo_errors::private::RegularVariantMetadata {
        name: "ConnectionFailed",
        message: "Database connection failed",
        code: "db::connection_failed",
        code_screaming_snake: "DB_CONNECTION_FAILED",
        code_camel: "dbConnectionFailed",
        code_pascal: "DbConnectionFailed",
        code_kebab: "db-connection-failed",
        http_status: 500u16,
        jsonrpc_code: -32000i32,
        help: None,
        url: Some("https://docs.example.com/errors/db-connection"),
        severity: None,
        fields: _APOLLO_ERROR_ERRORWITHURL_FIELDS_CONNECTIONFAILED,
    }),
];
static _APOLLO_ERROR_ERRORWITHURL_METADATA: ::apollo_errors::private::ErrorMetadata = ::apollo_errors::private::ErrorMetadata {
    type_name: "ErrorWithUrl",
    variants: _APOLLO_ERROR_ERRORWITHURL_VARIANTS,
};
fn _apollo_error_errorwithurl_render_json(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<
    ::std::result::Result<
        ::apollo_errors::private::serde_json::Value,
        ::apollo_errors::private::serde_json::Error,
    >,
> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::to_json(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_json(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_json(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(::apollo_errors::Error::to_json(box_arc.as_ref().as_ref(), config));
    }
    None
}
fn _apollo_error_errorwithurl_render_html(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<String> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::to_html(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_html(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_html(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(::apollo_errors::Error::to_html(box_arc.as_ref().as_ref(), config));
    }
    None
}
fn _apollo_error_errorwithurl_render_graphql(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<
    ::std::result::Result<
        ::apollo_errors::private::serde_json::Value,
        ::apollo_errors::private::serde_json::Error,
    >,
> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::to_graphql(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_graphql(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_graphql(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(
            ::apollo_errors::Error::to_graphql(box_arc.as_ref().as_ref(), config),
        );
    }
    None
}
fn _apollo_error_errorwithurl_render_text(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<String> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::to_text(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_text(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_text(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(::apollo_errors::Error::to_text(box_arc.as_ref().as_ref(), config));
    }
    None
}
fn _apollo_error_errorwithurl_http_status(
    error: &(dyn std::error::Error + 'static),
) -> Option<::apollo_errors::http::StatusCode> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::http_status(concrete));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::http_status(boxed.as_ref()));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::http_status(arc.as_ref()));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(::apollo_errors::Error::http_status(box_arc.as_ref().as_ref()));
    }
    None
}
fn _apollo_error_errorwithurl_render_jsonrpc(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<
    ::std::result::Result<
        ::apollo_errors::private::serde_json::Value,
        ::apollo_errors::private::serde_json::Error,
    >,
> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::to_jsonrpc(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_jsonrpc(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::to_jsonrpc(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(
            ::apollo_errors::Error::to_jsonrpc(box_arc.as_ref().as_ref(), config),
        );
    }
    None
}
fn _apollo_error_errorwithurl_http_headers(
    error: &(dyn std::error::Error + 'static),
) -> Option<
    Vec<(::apollo_errors::http::HeaderName, ::apollo_errors::http::HeaderValue)>,
> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithUrl>() {
        return Some(::apollo_errors::Error::http_headers(concrete));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::http_headers(boxed.as_ref()));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithUrl>>() {
        return Some(::apollo_errors::Error::http_headers(arc.as_ref()));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithUrl>>>() {
        return Some(::apollo_errors::Error::http_headers(box_arc.as_ref().as_ref()));
    }
    None
}
#[::apollo_errors::private::linkme::distributed_slice(
    ::apollo_errors::private::ERROR_REGISTRY
)]
#[linkme(crate = ::apollo_errors::private::linkme)]
#[doc(hidden)]
static _APOLLO_ERROR_ERRORWITHURL_REGISTRY_ENTRY: ::apollo_errors::private::ErrorRegistryEntry = ::apollo_errors::private::ErrorRegistryEntry {
    type_id: std::any::TypeId::of::<ErrorWithUrl>(),
    type_name: "ErrorWithUrl",
    metadata: &_APOLLO_ERROR_ERRORWITHURL_METADATA,
    render_json: _apollo_error_errorwithurl_render_json,
    render_html: _apollo_error_errorwithurl_render_html,
    render_graphql: _apollo_error_errorwithurl_render_graphql,
    render_text: _apollo_error_errorwithurl_render_text,
    http_status: _apollo_error_errorwithurl_http_status,
    render_jsonrpc: _apollo_error_errorwithurl_render_jsonrpc,
    http_headers: _apollo_error_errorwithurl_http_headers,
};
