<commit_before>// Copyright 2016 Serde YAML Developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::error;
use std::fmt::{self, Display};
use std::io;
use std::result;
use std::str;
use std::string;

use yaml_rust::{emitter, scanner};

use serde::{de, ser};

/// This type represents all possible errors that can occur when serializing or
/// deserializing a value using YAML.
#[derive(Debug)]
pub enum Error {
    Custom(String),
    EndOfStream,

    Emit(emitter::EmitError),
    Scan(scanner::ScanError),
    Io(io::Error),
    Utf8(str::Utf8Error),
    FromUtf8(string::FromUtf8Error),

    AliasNotFound,
    MoreThanOneDocument,
    VariantMapWrongSize(String, usize),
    VariantNotAMapOrString(String),
}

impl error::Error for Error {
    fn description(&self) -> &str {
        match *self {
            Error::Custom(_) => "syntax error",
            Error::EndOfStream => "EOF while parsing a value",
            Error::Emit(_) => "emit error",
            Error::Scan(_) => "scan error",
            Error::Io(ref err) => err.description(),
            Error::Utf8(ref err) => err.description(),
            Error::FromUtf8(ref err) => err.description(),
            Error::AliasNotFound => "alias not found",
            Error::MoreThanOneDocument => {
                "deserializing from YAML containing more than one document is not supported"
            }
            Error::VariantMapWrongSize(..) => {
                "expected a YAML map of size 1 while parsing variant"
            }
            Error::VariantNotAMapOrString(_) => {
                "expected a YAML map or string while parsing variant"
            }
        }
    }
<commit_msg>Better error description for custom error<commit_after>// Copyright 2016 Serde YAML Developers
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use std::error;
use std::fmt::{self, Display};
use std::io;
use std::result;
use std::str;
use std::string;

use yaml_rust::{emitter, scanner};

use serde::{de, ser};

/// This type represents all possible errors that can occur when serializing or
/// deserializing a value using YAML.
#[derive(Debug)]
pub enum Error {
    Custom(String),
    EndOfStream,

    Emit(emitter::EmitError),
    Scan(scanner::ScanError),
    Io(io::Error),
    Utf8(str::Utf8Error),
    FromUtf8(string::FromUtf8Error),

    AliasNotFound,
    MoreThanOneDocument,
    VariantMapWrongSize(String, usize),
    VariantNotAMapOrString(String),
}

impl error::Error for Error {
    fn description(&self) -> &str {
        match *self {
            Error::Custom(ref msg) => msg,
            Error::EndOfStream => "EOF while parsing a value",
            Error::Emit(_) => "emit error",
            Error::Scan(_) => "scan error",
            Error::Io(ref err) => err.description(),
            Error::Utf8(ref err) => err.description(),
            Error::FromUtf8(ref err) => err.description(),
            Error::AliasNotFound => "alias not found",
            Error::MoreThanOneDocument => {
                "deserializing from YAML containing more than one document is not supported"
            }
            Error::VariantMapWrongSize(..) => {
                "expected a YAML map of size 1 while parsing variant"
            }
            Error::VariantNotAMapOrString(_) => {
                "expected a YAML map or string while parsing variant"
            }
        }
    }

{'fraction_non_alphanumeric': 0.1262509622786759, 'fraction_numerical': 0.007698229407236336, 'mean_word_length': 2.649812734082397, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2083317', 'n_tokens_mistral': 1150, 'n_tokens_neox': 1111, 'n_words': 329}