<commit_before>
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use std::convert::From;
use std::io::Error as IoError;
use std::error::Error as StdError;
use std::fmt;

/// A trait for Errors produced by the consumer of this library
pub trait UserError: StdError { }

/// These are errors returned to the caller
#[derive(Debug)]
pub enum OAuthError<E: UserError> {
    Utf8Error(Utf8Error),
    FromUtf8Error(FromUtf8Error),
    Url(::url::ParseError),
    Io(IoError),
    AuthzBadRequest,
    AuthzMissingClientId,
    AuthzUnknownClient,
    AuthzRedirectUrlNotRegistered,
    AuthzGrantTypeMissing,
    AuthzClientIdMismatch,
    ClientCodeMissing,
    ClientStateMissing,
    ClientNonceMismatch,
    UnexpectedStatusCode,
    UserError(E),
}

impl<E: UserError> fmt::Display for OAuthError<E> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
    {
        match *self {
            OAuthError::Utf8Error(ref e) => e.fmt(f),
            OAuthError::FromUtf8Error(ref e) => e.fmt(f),
            OAuthError::Url(ref e) => e.fmt(f),
            OAuthError::Io(ref e) => e.fmt(f),
            OAuthError::UserError(ref e) => fmt::Display::fmt(e,f),
            ref e => write!(f, "{}", e.description()),
        }
    }
}

impl<E: UserError> StdError for OAuthError<E> {
    fn description(&self) -> &str {
        match *self {
            OAuthError::Utf8Error(ref e) => e.description(),
            OAuthError::FromUtf8Error(ref e) => e.description(),
            OAuthError::Url(ref e) => e.description(),
            OAuthError::Io(ref e) => e.description(),
            OAuthError::AuthzBadRequest => "Bad Request",
            OAuthError::AuthzMissingClientId => "Missing `client_id`",
            OAuthError::AuthzUnknownClient => "Unknown Client",
            OAuthError::AuthzRedirectUrlNotRegistered => "`redirect_url` Not Registered",
            OAuthError::AuthzGrantTypeMissing => "`grant_type` Missing",
            OAuthError::AuthzClientIdMismatch => "`client_id` mismatch",
            OAuthError::ClientCodeMissing => "`code` Missing",
            OAuthError::ClientStateMissing => "`state` Missing",
            OAuthError::ClientNonceMismatch => "`nonce` Mismatch",
            OAuthError::UnexpectedStatusCode => "Unexpected HTTP Status Code",
            OAuthError::UserError(ref e) => e.description(),
        }
    }

    fn cause(&self) -> Option<&StdError> {
        match *self {
            OAuthError::Utf8Error(ref e) => Some(e),
            OAuthError::FromUtf8Error(ref e) => Some(e),
            OAuthError::Url(ref e) => Some(e),
            OAuthError::Io(ref e) => Some(e),
            OAuthError::UserError(ref e) => Some(e),
            _ => None,
        }
    }
}

impl<E: UserError> From<Utf8Error> for OAuthError<E> {
    fn from(e: Utf8Error) -> OAuthError<E> {
        OAuthError::Utf8Error(e)
    }
}

impl<E: UserError> From<FromUtf8Error> for OAuthError<E> {
    fn from(e: FromUtf8Error) -> OAuthError<E> {
        OAuthError::FromUtf8Error(e)
    }
}

impl<E: UserError> From<::url::ParseError> for OAuthError<E> {
    fn from(e: ::url::ParseError) -> OAuthError<E> {
        OAuthError::Url(e)
    }
}

impl<E: UserError> From<IoError> for OAuthError<E> {
    fn from(e: IoError) -> OAuthError<E> {
        OAuthError::Io(e)
    }
}

impl<E: UserError> From<E> for OAuthError<E> {
    fn from(e: E) -> OAuthError<E> {
        OAuthError::UserError(e)
    }<commit_msg>OAuthError::ParseInt<commit_after>
use std::str::Utf8Error;
use std::string::FromUtf8Error;
use std::convert::From;
use std::io::Error as IoError;
use std::num::ParseIntError;
use std::error::Error as StdError;
use std::fmt;

/// A trait for Errors produced by the consumer of this library
pub trait UserError: StdError { }

/// These are errors returned to the caller
#[derive(Debug)]
pub enum OAuthError<E: UserError> {
    Utf8Error(Utf8Error),
    FromUtf8Error(FromUtf8Error),
    Url(::url::ParseError),
    Io(IoError),
    ParseInt(ParseIntError),
    AuthzBadRequest,
    AuthzMissingClientId,
    AuthzUnknownClient,
    AuthzRedirectUrlNotRegistered,
    AuthzGrantTypeMissing,
    AuthzClientIdMismatch,
    AuthzGrantNotFound,
    ClientCodeMissing,
    ClientStateMissing,
    ClientNonceMismatch,
    UnexpectedStatusCode,
    UserError(E),
}

impl<E: UserError> fmt::Display for OAuthError<E> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result
    {
        match *self {
            OAuthError::Utf8Error(ref e) => e.fmt(f),
            OAuthError::FromUtf8Error(ref e) => e.fmt(f),
            OAuthError::Url(ref e) => e.fmt(f),
            OAuthError::Io(ref e) => e.fmt(f),
            OAuthError::ParseInt(ref e) => e.fmt(f),
            OAuthError::UserError(ref e) => fmt::Display::fmt(e,f),
            ref e => write!(f, "{}", e.description()),
        }
    }
}

impl<E: UserError> StdError for OAuthError<E> {
    fn description(&self) -> &str {
        match *self {
            OAuthError::Utf8Error(ref e) => e.description(),
            OAuthError::FromUtf8Error(ref e) => e.description(),
            OAuthError::Url(ref e) => e.description(),
            OAuthError::Io(ref e) => e.description(),
            OAuthError::ParseInt(ref e) => e.description(),
            OAuthError::AuthzBadRequest => "Bad Request",
            OAuthError::AuthzMissingClientId => "Missing `client_id`",
            OAuthError::AuthzUnknownClient => "Unknown Client",
            OAuthError::AuthzRedirectUrlNotRegistered => "`redirect_url` Not Registered",
            OAuthError::AuthzGrantTypeMissing => "`grant_type` Missing",
            OAuthError::AuthzClientIdMismatch => "`client_id` mismatch",
            OAuthError::AuthzGrantNotFound => "grant not found",
            OAuthError::ClientCodeMissing => "`code` Missing",
            OAuthError::ClientStateMissing => "`state` Missing",
            OAuthError::ClientNonceMismatch => "`nonce` Mismatch",
            OAuthError::UnexpectedStatusCode => "Unexpected HTTP Status Code",
            OAuthError::UserError(ref e) => e.description(),
        }
    }

    fn cause(&self) -> Option<&StdError> {
        match *self {
            OAuthError::Utf8Error(ref e) => Some(e),
            OAuthError::FromUtf8Error(ref e) => Some(e),
            OAuthError::Url(ref e) => Some(e),
            OAuthError::Io(ref e) => Some(e),
            OAuthError::ParseInt(ref e) => Some(e),
            OAuthError::UserError(ref e) => Some(e),
            _ => None,
        }
    }
}

impl<E: UserError> From<Utf8Error> for OAuthError<E> {
    fn from(e: Utf8Error) -> OAuthError<E> {
        OAuthError::Utf8Error(e)
    }
}

impl<E: UserError> From<FromUtf8Error> for OAuthError<E> {
    fn from(e: FromUtf8Error) -> OAuthError<E> {
        OAuthError::FromUtf8Error(e)
    }
}

impl<E: UserError> From<::url::ParseError> for OAuthError<E> {
    fn from(e: ::url::ParseError) -> OAuthError<E> {
        OAuthError::Url(e)
    }
}

impl<E: UserError> From<IoError> for OAuthError<E> {
    fn from(e: IoError) -> OAuthError<E> {
        OAuthError::Io(e)
    }
}

impl<E: UserError> From<ParseIntError> for OAuthError<E> {
    fn from(e: ParseIntError) -> OAuthError<E> {
        OAuthError::ParseInt(e)
    }
}

impl<E: UserError> From<E> for OAuthError<E> {
    fn from(e: E) -> OAuthError<E> {
        OAuthError::UserError(e)
    }
{'fraction_non_alphanumeric': 0.14649075081610446, 'fraction_numerical': 0.004896626768226333, 'mean_word_length': 2.9638814016172508, 'pattern_counts': {'":': 0, '<': 59, '<?xml version=': 0, '>': 134, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5644243', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2471, 'n_words': 467}