---
source: apollo-errors/crates/apollo-errors-derive/src/tests.rs
expression: pretty_print(output)
---
#[automatically_derived]
impl ::std::fmt::Display for ErrorWithFields {
    fn fmt(
        &self,
        __apollo_formatter: &mut ::std::fmt::Formatter<'_>,
    ) -> ::std::fmt::Result {
        match self {
            Self::InvalidPort { port, config_file } => {
                write!(__apollo_formatter, "Invalid port")
            }
        }
    }
}
#[automatically_derived]
impl ::std::error::Error for ErrorWithFields {
    fn source(&self) -> ::std::option::Option<&(dyn ::std::error::Error + 'static)> {
        match self {
            Self::InvalidPort { port, config_file } => ::std::option::Option::None,
        }
    }
}
#[automatically_derived]
impl ::apollo_errors::Error for ErrorWithFields {
    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::InvalidPort { port, config_file } => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => "config::invalid_port",
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "CONFIG_INVALID_PORT"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "configInvalidPort",
                    ::apollo_errors::private::CodeCase::PascalCase => "ConfigInvalidPort",
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "config-invalid-port"
                    }
                };
                let __apollo_message = ::std::string::ToString::to_string(self);
                let mut __apollo_obj = ::apollo_errors::private::serde_json::json!(
                    { "error" : __apollo_code, "message" : __apollo_message }
                );
                if let ::apollo_errors::private::serde_json::Value::Object(
                    ref mut __apollo_map,
                ) = __apollo_obj {
                    if let ::std::option::Option::Some((__apollo_key, __apollo_value)) = ::std::option::Option::Some((
                        match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => "port",
                            ::apollo_errors::private::FieldCase::CamelCase => "port",
                            ::apollo_errors::private::FieldCase::PascalCase => "Port",
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase => {
                                "PORT"
                            }
                            ::apollo_errors::private::FieldCase::KebabCase => "port",
                        },
                        ::apollo_errors::private::serde_json::to_value(port)
                            .unwrap_or(::apollo_errors::private::serde_json::Value::Null),
                    )) {
                        __apollo_map.insert(__apollo_key.to_string(), __apollo_value);
                    }
                    if let ::std::option::Option::Some((__apollo_key, __apollo_value)) = ::std::option::Option::Some((
                        match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => {
                                "config_file"
                            }
                            ::apollo_errors::private::FieldCase::CamelCase => {
                                "configFile"
                            }
                            ::apollo_errors::private::FieldCase::PascalCase => {
                                "ConfigFile"
                            }
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase => {
                                "CONFIG_FILE"
                            }
                            ::apollo_errors::private::FieldCase::KebabCase => {
                                "config-file"
                            }
                        },
                        ::apollo_errors::private::serde_json::to_value(config_file)
                            .unwrap_or(::apollo_errors::private::serde_json::Value::Null),
                    )) {
                        __apollo_map.insert(__apollo_key.to_string(), __apollo_value);
                    }
                }
                ::std::result::Result::Ok(__apollo_obj)
            }
        }
    }
    fn to_html(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::string::String {
        match self {
            Self::InvalidPort { port, config_file } => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => "config::invalid_port",
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "CONFIG_INVALID_PORT"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "configInvalidPort",
                    ::apollo_errors::private::CodeCase::PascalCase => "ConfigInvalidPort",
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "config-invalid-port"
                    }
                };
                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 = {
                    let mut __apollo_fields: Vec<::std::string::String> = Vec::new();
                    if let ::std::option::Option::Some(__apollo_field_html) = ::std::option::Option::Some(
                        format!(
                            "<div class=\"error-field\"><span class=\"field-name\">{}:</span> <span class=\"field-value\">{}</span></div>",
                            match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => "port",
                            ::apollo_errors::private::FieldCase::CamelCase => "port",
                            ::apollo_errors::private::FieldCase::PascalCase => "Port",
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase =>
                            "PORT", ::apollo_errors::private::FieldCase::KebabCase =>
                            "port", }, ::apollo_errors::private::HtmlEscaped(port)
                        ),
                    ) {
                        __apollo_fields.push(__apollo_field_html);
                    }
                    if let ::std::option::Option::Some(__apollo_field_html) = ::std::option::Option::Some(
                        format!(
                            "<div class=\"error-field\"><span class=\"field-name\">{}:</span> <span class=\"field-value\">{}</span></div>",
                            match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase =>
                            "config_file", ::apollo_errors::private::FieldCase::CamelCase
                            => "configFile",
                            ::apollo_errors::private::FieldCase::PascalCase =>
                            "ConfigFile",
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase =>
                            "CONFIG_FILE", ::apollo_errors::private::FieldCase::KebabCase
                            => "config-file", },
                            ::apollo_errors::private::HtmlEscaped(config_file)
                        ),
                    ) {
                        __apollo_fields.push(__apollo_field_html);
                    }
                    if __apollo_fields.is_empty() {
                        ::std::string::String::new()
                    } else {
                        format!(
                            "\n<div class=\"error-extensions\">\n{}\n</div>",
                            __apollo_fields.join("\n")
                        )
                    }
                };
                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::InvalidPort { port, config_file } => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => "config::invalid_port",
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "CONFIG_INVALID_PORT"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "configInvalidPort",
                    ::apollo_errors::private::CodeCase::PascalCase => "ConfigInvalidPort",
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "config-invalid-port"
                    }
                };
                let __apollo_message = ::std::string::ToString::to_string(self);
                let mut __apollo_extensions = ::apollo_errors::private::serde_json::json!(
                    { "code" : __apollo_code }
                );
                if let ::apollo_errors::private::serde_json::Value::Object(
                    ref mut __apollo_map,
                ) = __apollo_extensions {
                    if let ::std::option::Option::Some((__apollo_key, __apollo_value)) = ::std::option::Option::Some((
                        match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => "port",
                            ::apollo_errors::private::FieldCase::CamelCase => "port",
                            ::apollo_errors::private::FieldCase::PascalCase => "Port",
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase => {
                                "PORT"
                            }
                            ::apollo_errors::private::FieldCase::KebabCase => "port",
                        },
                        ::apollo_errors::private::serde_json::to_value(port)
                            .unwrap_or(::apollo_errors::private::serde_json::Value::Null),
                    )) {
                        __apollo_map.insert(__apollo_key.to_string(), __apollo_value);
                    }
                    if let ::std::option::Option::Some((__apollo_key, __apollo_value)) = ::std::option::Option::Some((
                        match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => {
                                "config_file"
                            }
                            ::apollo_errors::private::FieldCase::CamelCase => {
                                "configFile"
                            }
                            ::apollo_errors::private::FieldCase::PascalCase => {
                                "ConfigFile"
                            }
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase => {
                                "CONFIG_FILE"
                            }
                            ::apollo_errors::private::FieldCase::KebabCase => {
                                "config-file"
                            }
                        },
                        ::apollo_errors::private::serde_json::to_value(config_file)
                            .unwrap_or(::apollo_errors::private::serde_json::Value::Null),
                    )) {
                        __apollo_map.insert(__apollo_key.to_string(), __apollo_value);
                    }
                }
                ::std::result::Result::Ok(
                    ::apollo_errors::private::serde_json::json!(
                        { "message" : __apollo_message, "extensions" :
                        __apollo_extensions }
                    ),
                )
            }
        }
    }
    fn to_text(
        &self,
        config: ::apollo_errors::private::FormatConfig,
    ) -> ::std::string::String {
        match self {
            Self::InvalidPort { port, config_file } => {
                let __apollo_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => "config::invalid_port",
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "CONFIG_INVALID_PORT"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "configInvalidPort",
                    ::apollo_errors::private::CodeCase::PascalCase => "ConfigInvalidPort",
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "config-invalid-port"
                    }
                };
                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::InvalidPort { port, config_file } => {
                let __apollo_diagnostic_code = match config.code_case {
                    ::apollo_errors::private::CodeCase::Default => "config::invalid_port",
                    ::apollo_errors::private::CodeCase::ScreamingSnakeCase => {
                        "CONFIG_INVALID_PORT"
                    }
                    ::apollo_errors::private::CodeCase::CamelCase => "configInvalidPort",
                    ::apollo_errors::private::CodeCase::PascalCase => "ConfigInvalidPort",
                    ::apollo_errors::private::CodeCase::KebabCase => {
                        "config-invalid-port"
                    }
                };
                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 {
                    if let ::std::option::Option::Some((__apollo_key, __apollo_value)) = ::std::option::Option::Some((
                        match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => "port",
                            ::apollo_errors::private::FieldCase::CamelCase => "port",
                            ::apollo_errors::private::FieldCase::PascalCase => "Port",
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase => {
                                "PORT"
                            }
                            ::apollo_errors::private::FieldCase::KebabCase => "port",
                        },
                        ::apollo_errors::private::serde_json::to_value(port)
                            .unwrap_or(::apollo_errors::private::serde_json::Value::Null),
                    )) {
                        __apollo_map.insert(__apollo_key.to_string(), __apollo_value);
                    }
                    if let ::std::option::Option::Some((__apollo_key, __apollo_value)) = ::std::option::Option::Some((
                        match config.field_case {
                            ::apollo_errors::private::FieldCase::SnakeCase => {
                                "config_file"
                            }
                            ::apollo_errors::private::FieldCase::CamelCase => {
                                "configFile"
                            }
                            ::apollo_errors::private::FieldCase::PascalCase => {
                                "ConfigFile"
                            }
                            ::apollo_errors::private::FieldCase::ScreamingSnakeCase => {
                                "CONFIG_FILE"
                            }
                            ::apollo_errors::private::FieldCase::KebabCase => {
                                "config-file"
                            }
                        },
                        ::apollo_errors::private::serde_json::to_value(config_file)
                            .unwrap_or(::apollo_errors::private::serde_json::Value::Null),
                    )) {
                        __apollo_map.insert(__apollo_key.to_string(), __apollo_value);
                    }
                }
                ::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::InvalidPort { port, config_file } => {
                ::http::StatusCode::INTERNAL_SERVER_ERROR
            }
        }
    }
    fn http_headers(
        &self,
    ) -> Vec<(::apollo_errors::http::HeaderName, ::apollo_errors::http::HeaderValue)> {
        match self {
            Self::InvalidPort { port, config_file } => Vec::new(),
        }
    }
}
static _APOLLO_ERROR_ERRORWITHFIELDS_FIELDS_INVALIDPORT: &[::apollo_errors::private::FieldMetadata] = &[
    ::apollo_errors::private::FieldMetadata {
        rust_name: "port",
        output_name: "port",
        snake_case: "port",
        camel_case: "port",
        pascal_case: "Port",
        screaming_snake_case: "PORT",
        kebab_case: "port",
        ty: "u16",
        is_extension: true,
        http_header: None,
    },
    ::apollo_errors::private::FieldMetadata {
        rust_name: "config_file",
        output_name: "config_file",
        snake_case: "config_file",
        camel_case: "configFile",
        pascal_case: "ConfigFile",
        screaming_snake_case: "CONFIG_FILE",
        kebab_case: "config-file",
        ty: "String",
        is_extension: true,
        http_header: None,
    },
];
static _APOLLO_ERROR_ERRORWITHFIELDS_VARIANTS: &[::apollo_errors::private::VariantMetadata] = &[
    ::apollo_errors::private::VariantMetadata::Regular(::apollo_errors::private::RegularVariantMetadata {
        name: "InvalidPort",
        message: "Invalid port",
        code: "config::invalid_port",
        code_screaming_snake: "CONFIG_INVALID_PORT",
        code_camel: "configInvalidPort",
        code_pascal: "ConfigInvalidPort",
        code_kebab: "config-invalid-port",
        http_status: 500u16,
        jsonrpc_code: -32000i32,
        help: None,
        url: None,
        severity: None,
        fields: _APOLLO_ERROR_ERRORWITHFIELDS_FIELDS_INVALIDPORT,
    }),
];
static _APOLLO_ERROR_ERRORWITHFIELDS_METADATA: ::apollo_errors::private::ErrorMetadata = ::apollo_errors::private::ErrorMetadata {
    type_name: "ErrorWithFields",
    variants: _APOLLO_ERROR_ERRORWITHFIELDS_VARIANTS,
};
fn _apollo_error_errorwithfields_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::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::to_json(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_json(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_json(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        return Some(::apollo_errors::Error::to_json(box_arc.as_ref().as_ref(), config));
    }
    None
}
fn _apollo_error_errorwithfields_render_html(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<String> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::to_html(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_html(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_html(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        return Some(::apollo_errors::Error::to_html(box_arc.as_ref().as_ref(), config));
    }
    None
}
fn _apollo_error_errorwithfields_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::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::to_graphql(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_graphql(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_graphql(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        return Some(
            ::apollo_errors::Error::to_graphql(box_arc.as_ref().as_ref(), config),
        );
    }
    None
}
fn _apollo_error_errorwithfields_render_text(
    error: &(dyn std::error::Error + 'static),
    config: ::apollo_errors::private::FormatConfig,
) -> Option<String> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::to_text(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_text(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_text(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        return Some(::apollo_errors::Error::to_text(box_arc.as_ref().as_ref(), config));
    }
    None
}
fn _apollo_error_errorwithfields_http_status(
    error: &(dyn std::error::Error + 'static),
) -> Option<::apollo_errors::http::StatusCode> {
    if let Some(concrete) = error.downcast_ref::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::http_status(concrete));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::http_status(boxed.as_ref()));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::http_status(arc.as_ref()));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        return Some(::apollo_errors::Error::http_status(box_arc.as_ref().as_ref()));
    }
    None
}
fn _apollo_error_errorwithfields_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::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::to_jsonrpc(concrete, config));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_jsonrpc(boxed.as_ref(), config));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::to_jsonrpc(arc.as_ref(), config));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        return Some(
            ::apollo_errors::Error::to_jsonrpc(box_arc.as_ref().as_ref(), config),
        );
    }
    None
}
fn _apollo_error_errorwithfields_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::<ErrorWithFields>() {
        return Some(::apollo_errors::Error::http_headers(concrete));
    }
    if let Some(boxed) = error.downcast_ref::<Box<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::http_headers(boxed.as_ref()));
    }
    if let Some(arc) = error.downcast_ref::<std::sync::Arc<ErrorWithFields>>() {
        return Some(::apollo_errors::Error::http_headers(arc.as_ref()));
    }
    if let Some(box_arc) = error.downcast_ref::<Box<std::sync::Arc<ErrorWithFields>>>() {
        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_ERRORWITHFIELDS_REGISTRY_ENTRY: ::apollo_errors::private::ErrorRegistryEntry = ::apollo_errors::private::ErrorRegistryEntry {
    type_id: std::any::TypeId::of::<ErrorWithFields>(),
    type_name: "ErrorWithFields",
    metadata: &_APOLLO_ERROR_ERRORWITHFIELDS_METADATA,
    render_json: _apollo_error_errorwithfields_render_json,
    render_html: _apollo_error_errorwithfields_render_html,
    render_graphql: _apollo_error_errorwithfields_render_graphql,
    render_text: _apollo_error_errorwithfields_render_text,
    http_status: _apollo_error_errorwithfields_http_status,
    render_jsonrpc: _apollo_error_errorwithfields_render_jsonrpc,
    http_headers: _apollo_error_errorwithfields_http_headers,
};
