<commit_before>use diesel::result;

use std::convert::From;
use std::error::Error;
use std::{fmt, io};

use self::DatabaseError::*;

pub type DatabaseResult<T> = Result<T, DatabaseError>;

#[derive(Debug)]
pub enum DatabaseError {
    CargoTomlNotFound,
    DatabaseUrlMissing,
    IoError(io::Error),
    QueryError(result::Error),
    ConnectionError(result::ConnectionError),
}

impl From<io::Error> for DatabaseError {
    fn from(e: io::Error) -> Self {
        IoError(e)
    }
}

impl From<result::Error> for DatabaseError {
    fn from(e: result::Error) -> Self {
        QueryError(e)
    }
}

impl From<result::ConnectionError> for DatabaseError {
    fn from(e: result::ConnectionError) -> Self {
        ConnectionError(e)
    }
}

impl Error for DatabaseError {
    fn description(&self) -> &str {
        match *self {
            CargoTomlNotFound => {
                "Unable to find Cargo.toml in this directory or any parent directories."
            }
            DatabaseUrlMissing => {
                "The --database-url argument must be passed, or the DATABASE_URL environment variable must be set."
            }
            IoError(ref error) => error
                .cause()
                .map(|e| e.description())
                .unwrap_or_else(|| error.description()),
            QueryError(ref error) => error
                .cause()
                .map(|e| e.description())
                .unwrap_or_else(|| error.description()),
            ConnectionError(ref error) => error
                .cause()
                .map(|e| e.description())
                .unwrap_or_else(|| error.description()),
        }
    }
}

impl fmt::Display for DatabaseError {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        self.description().fmt(f)
    }
}

impl PartialEq for DatabaseError {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (&CargoTomlNotFound, &CargoTomlNotFound) => true,
            _ => false,
        }<commit_msg>diesel_cli: Change from Error::cause() to Error::source()<commit_after>use diesel::result;

use std::convert::From;
use std::error::Error;
use std::{fmt, io};

use self::DatabaseError::*;

pub type DatabaseResult<T> = Result<T, DatabaseError>;

#[derive(Debug)]
pub enum DatabaseError {
    CargoTomlNotFound,
    DatabaseUrlMissing,
    IoError(io::Error),
    QueryError(result::Error),
    ConnectionError(result::ConnectionError),
}

impl From<io::Error> for DatabaseError {
    fn from(e: io::Error) -> Self {
        IoError(e)
    }
}

impl From<result::Error> for DatabaseError {
    fn from(e: result::Error) -> Self {
        QueryError(e)
    }
}

impl From<result::ConnectionError> for DatabaseError {
    fn from(e: result::ConnectionError) -> Self {
        ConnectionError(e)
    }
}

impl Error for DatabaseError {
    fn description(&self) -> &str {
        match *self {
            CargoTomlNotFound => {
                "Unable to find Cargo.toml in this directory or any parent directories."
            }
            DatabaseUrlMissing => {
                "The --database-url argument must be passed, or the DATABASE_URL environment variable must be set."
            }
            IoError(ref error) => error
                .source()
                .map(|e| e.description())
                .unwrap_or_else(|| error.description()),
            QueryError(ref error) => error
                .source()
                .map(|e| e.description())
                .unwrap_or_else(|| error.description()),
            ConnectionError(ref error) => error
                .source()
                .map(|e| e.description())
                .unwrap_or_else(|| error.description()),
        }
    }
}

impl fmt::Display for DatabaseError {
    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
        self.description().fmt(f)
    }
}

impl PartialEq for DatabaseError {
    fn eq(&self, other: &Self) -> bool {
        match (self, other) {
            (&CargoTomlNotFound, &CargoTomlNotFound) => true,
            _ => false,
        }
{'fraction_non_alphanumeric': 0.13364280478866358, 'fraction_numerical': 0.0, 'mean_word_length': 2.1984375, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 41, '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': '6416257', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1166, 'n_words': 285}