<commit_before>//! Our error enum.

use std::num::ParseFloatError;
use std::str::ParseBoolError;

use las;
#[cfg(feature = "rxp-source")]
use rivlib;
use sdc;
#[cfg(feature = "sdf-source")]
use sdf;

/// Our custom error handling type.
#[derive(Debug)]
pub enum Error {
    /// Invalid options to a source or sink.
    InvalidOption(String),
    /// A point is missing a dimension that is required by someone else, usually a `Sink`.
    MissingDimension(String),
    /// A wrapper around a las error.
    Las(las::Error),
    /// A wrapper around `std::str::ParseBoolError`.
    ParseBool(ParseBoolError),
    /// A wrapper around `std::num::ParseFloatError`.
    ParseFloat(ParseFloatError),
    #[cfg(feature = "rxp-source")]
    /// A wrapper around an rxp error.
    Rxp(rivlib::Error),
    /// A wrapper around an sdc error.
    Sdc(sdc::Error),
    #[cfg(feature = "sdf-source")]
    /// A wrapper around an sdf error.
    Sdf(sdf::Error),
    /// The type of sink could not be determined.
    UndefinedSink,
    /// The type of source could not be determined.
    UndefinedSource,
}

impl From<las::Error> for Error {
    fn from(err: las::Error) -> Error {
        Error::Las(err)<commit_msg>Implement error for Error<commit_after>//! Our error enum.

use std::error;
use std::fmt;
use std::num::ParseFloatError;
use std::str::ParseBoolError;

use las;
#[cfg(feature = "rxp-source")]
use rivlib;
use sdc;
#[cfg(feature = "sdf-source")]
use sdf;

/// Our custom error handling type.
#[derive(Debug)]
pub enum Error {
    /// Invalid options to a source or sink.
    InvalidOption(String),
    /// A point is missing a dimension that is required by someone else, usually a `Sink`.
    MissingDimension(String),
    /// A wrapper around a las error.
    Las(las::Error),
    /// A wrapper around `std::str::ParseBoolError`.
    ParseBool(ParseBoolError),
    /// A wrapper around `std::num::ParseFloatError`.
    ParseFloat(ParseFloatError),
    #[cfg(feature = "rxp-source")]
    /// A wrapper around an rxp error.
    Rxp(rivlib::Error),
    /// A wrapper around an sdc error.
    Sdc(sdc::Error),
    #[cfg(feature = "sdf-source")]
    /// A wrapper around an sdf error.
    Sdf(sdf::Error),
    /// The type of sink could not be determined.
    UndefinedSink,
    /// The type of source could not be determined.
    UndefinedSource,
}

impl error::Error for Error {
    fn description(&self) -> &str {
        match *self {
            Error::InvalidOption(_) => "invalid option",
            Error::MissingDimension(_) => "missing dimension",
            Error::Las(ref err) => err.description(),
            Error::ParseBool(ref err) => err.description(),
            Error::ParseFloat(ref err) => err.description(),
            #[cfg(feature = "rxp-source")]
            Error::Rxp(ref err) => err.description(),
            Error::Sdc(ref err) => err.description(),
            #[cfg(feature = "sdf-source")]
            Error::Sdf(ref err) => err.description(),
            Error::UndefinedSink => "undefined sink",
            Error::UndefinedSource => "undefined source",
        }
    }

    fn cause(&self) -> Option<&error::Error> {
        match *self {
            Error::Las(ref err) => Some(err),
            Error::ParseBool(ref err) => Some(err),
            Error::ParseFloat(ref err) => Some(err),
            #[cfg(feature = "rxp-source")]
            Error::Rxp(ref err) => Some(err),
            Error::Sdc(ref err) => Some(err),
            #[cfg(feature = "sdf-source")]
            Error::Sdf(ref err) => Some(err),
            _ => None,
        }
    }
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        match *self {
            Error::InvalidOption(ref s) => write!(f, "Invalid option: {}", s),
            Error::MissingDimension(ref s) => write!(f, "Missing dimension: {}", s),
            Error::Las(ref err) => write!(f, "las error: {}", err),
            Error::ParseBool(ref err) => write!(f, "Parse bool error: {}", err),
            Error::ParseFloat(ref err) => write!(f, "Parse float error: {}", err),
            #[cfg(feature = "rxp-source")]
            Error::Rxp(ref err) => write!(f, "rxp error: {}", err),
            Error::Sdc(ref err) => write!(f, "sdc error: {}", err),
            #[cfg(feature = "sdf-source")]
            Error::Sdf(ref err) => write!(f, "sdf error: {}", err),
            Error::UndefinedSink => write!(f, "Undefined sink"),
            Error::UndefinedSource => write!(f, "Undefined source"),
        }
    }
}

impl From<las::Error> for Error {
    fn from(err: las::Error) -> Error {
        Error::Las(err)
{'fraction_non_alphanumeric': 0.16515739542906424, 'fraction_numerical': 0.0, 'mean_word_length': 2.5850077279752703, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 38, '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': '6761132', 'n_tokens_mistral': 1399, 'n_tokens_neox': 1424, 'n_words': 395}