Refactored (simplified) errors.

[?]
Jun 30, 2021, 1:46 AM
N467KW7J7K5T6THQV2EACLUC4AEDR74TNNKRQCYTZTBMBUJUVRTAC

Dependencies

Change contents

  • replacement in src/parser.rs at line 5
    [3.2330][2.0:21](),[2.21][3.2368:2395](),[3.2368][3.2368:2395]()
    use crate::error::*;
    use crate::{Line, Result};
    [3.2330]
    [3.2395]
    use crate::error::Error;
    use crate::error::{
    bad_indent,
    colon_before_key,
    empty_string,
    first_token_must_be_key,
    incomplete_comment_or_key,
    incomplete_line,
    no_colon_after_key,
    no_space_after_key,
    no_tokens,
    non_root_has_zero_indent,
    };
    use crate::Result;
  • edit in src/parser.rs at line 35
    [3.2768][2.22:150](),[2.150][3.2768:2769](),[3.2768][3.2768:2769](),[3.2769][2.151:500]()
    // Relays error back to a function which knowns the token. (chars indented relative to root key)
    struct InnerBadIndent(usize);
    impl InnerBadIndent {
    fn from_inner(token: &Token, line: Line) -> std::result::Result<u32, Error> {
    bad_indent
    let indent = indent(
    &mut root_indent,
    line_start,
    start_key
    ).map_err(|err| err.from_inner(&token, line))?;
  • edit in src/parser.rs at line 36
    [2.501]
    [2.501]
    pub struct BadIndent(usize);
  • edit in src/parser.rs at line 38
    [2.502]
    [2.502]
    impl BadIndent {
    // Maps InnerBadIndent to Error.
    fn from_inner(
    self,
    token: &Token,
    line: usize) -> Error
    {
    bad_indent(&token.to_string(), line, self.0)
    }
  • replacement in src/parser.rs at line 122
    [3.4577][2.506:570]()
    Err(first_token_must_be_key(token.to_string()))
    [3.4577]
    [3.4660]
    Err(first_token_must_be_key(&token.to_string()))
  • replacement in src/parser.rs at line 164
    [3.6106][2.571:619](),[2.619][3.6176:6219](),[3.6176][3.6176:6219]()
    return Err(non_root_indent(
    token.to_string(),
    [3.6106]
    [3.6219]
    return Err(non_root_has_zero_indent(
    &token.to_string(),
  • replacement in src/parser.rs at line 290
    [3.10651][3.10651:10704]()
    line: Line::new(line),
    [3.10651]
    [3.10704]
    line: line,
  • replacement in src/parser.rs at line 306
    [3.11255][3.11255:11308]()
    line: Line::new(line),
    [3.11255]
    [3.11308]
    line: line,
  • replacement in src/parser.rs at line 322
    [3.11869][3.11869:11918]()
    line: Line::new(line),
    [3.11869]
    [3.11918]
    line: line,
  • replacement in src/parser.rs at line 379
    [2.841][3.922:972](),[3.922][3.922:972]()
    token_str.to_string()
    [2.841]
    [3.972]
    &token_str.to_string()
  • replacement in src/parser.rs at line 386
    [2.898][3.1066:1125](),[3.1066][3.1066:1125](),[3.1125][3.0:51](),[3.51][3.115:164]()
    ErrorKind::IncompleteCommentOrKey(
    token_str.to_string(),
    Line::new(line + 1),
    [2.898]
    [3.1175]
    incomplete_comment_or_key(
    &token_str.to_string(),
    line + 1,
  • replacement in src/parser.rs at line 396
    [3.13974][2.922:977]()
    return Err(non_space_after_key());
    [3.13974]
    [3.14046]
    return Err(no_space_after_key());
  • replacement in src/parser.rs at line 405
    [2.1051][3.32:124](),[3.1439][3.32:124]()
    String::from("/"),
    Line::new(line),
    [2.1051]
    [3.1485]
    &String::from("/"),
    line,
  • replacement in src/parser.rs at line 415
    [2.1148][3.157:253](),[3.1629][3.157:253]()
    token_str.to_string(),
    Line::new(line),
    [2.1148]
    [3.1679]
    &token_str.to_string(),
    line,
  • replacement in src/parser.rs at line 438
    [3.15385][2.1331:1382]()
    return Err(no_space_after_key)
    [3.15385]
    [3.15457]
    return Err(no_space_after_key())
  • replacement in src/parser.rs at line 453
    [2.1458][3.2501:2548](),[3.2501][3.2501:2548](),[3.2548][3.194:235]()
    token_str.to_string(),
    Line::new(line),
    [2.1458]
    [3.2548]
    &token_str.to_string(),
    line,
  • replacement in src/parser.rs at line 463
    [2.1543][3.282:370](),[3.2677][3.282:370]()
    token_str.to_string(),
    Line::new(line),
    [2.1543]
    [3.2723]
    &token_str.to_string(),
    line,
  • replacement in src/parser.rs at line 474
    [3.2903][3.2903:2946]()
    line: Line::new(line),
    [3.2903]
    [3.16351]
    line: line,
  • replacement in src/parser.rs at line 489
    [3.16795][3.16795:16844]()
    line: Line::new(line),
    [3.16795]
    [3.16844]
    line: line,
  • replacement in src/parser.rs at line 504
    [3.3469][3.3469:3512]()
    line: Line::new(line),
    [3.3469]
    [3.17339]
    line: line,
  • replacement in src/parser.rs at line 517
    [3.17635][3.17635:17684]()
    Err(Error::new(ErrorKind::NoTokens))
    [3.17635]
    [3.17684]
    Err(no_tokens())
  • replacement in src/parser.rs at line 528
    [3.17883][2.1563:1636]()
    start_key: usize) -> std::result::Result<usize, InnerBadIndent>
    [3.17883]
    [3.17927]
    start_key: usize) -> std::result::Result<usize, BadIndent>
  • replacement in src/parser.rs at line 543
    [3.18249][2.1637:1694]()
    return Err(InnerBadIndent(chars_indent))
    [3.18249]
    [3.18330]
    return Err(BadIndent(chars_indent))
  • replacement in src/lib.rs at line 5
    [3.18484][3.18484:18526]()
    pub use crate::error::{Error, ErrorKind};
    [3.18484]
    [3.18526]
    pub use crate::error::Error;
    pub use crate::error::{
    bad_first_segment,
    empty_path,
    expected_key_found_keyvalue,
    expected_unique_token_found_multi,
    failed_to_parse_value,
    no_child_with_segment,
    };
  • edit in src/lib.rs at line 26
    [3.19003][3.4026:4072](),[3.4072][3.19003:19268](),[3.19003][3.19003:19268]()
    /// Indicates line number for error messages.
    #[derive(Clone, Copy, Debug)]
    pub struct Line(usize);
    impl Line {
    pub fn new(line: usize) -> Self {
    Line(line)
    }
    }
    impl fmt::Display for Line {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
    write!(f, "{}", self.0)
    }
    }
  • replacement in src/lib.rs at line 34
    [3.19511][3.19511:19568]()
    line: Line, // used for debugging
    [3.19511]
    [3.19568]
    line: usize,
  • replacement in src/lib.rs at line 40
    [3.19714][3.19714:19771]()
    line: Line, // used for debugging
    [3.19714]
    [3.19771]
    line: usize,
  • replacement in src/lib.rs at line 46
    [3.19803][3.19803:19836]()
    pub fn line(&self) -> Line {
    [3.19803]
    [3.19836]
    pub fn line(&self) -> usize {
  • replacement in src/lib.rs at line 169
    [3.373][3.373:437]()
    _ => Err(Error::new(ErrorKind::EUniqueTokenFMany)),
    [3.373]
    [3.31]
    _ => Err(expected_unique_token_found_multi()),
  • replacement in src/lib.rs at line 182
    [3.294][3.294:661](),[3.661][3.437:453](),[3.437][3.437:453]()
    pub fn keyvalue_into<T>(&self) -> Result<T>
    where
    T: FromStr
    {
    match T::from_str(self.top_value().value) {
    Ok(t) => Ok(t),
    Err(err) => {
    Err(Error::new(ErrorKind::FromStr(
    format!("{}: {}", key, value),
    format!("{}", kt.1),
    )))
    },
    }
    }
    [3.294]
    [3.453]
    // pub fn keyvalue_into<T>(&self) -> Result<T>
    // where
    // T: FromStr
    // {
    // match T::from_str(self.top_value().value) {
    // Ok(t) => Ok(t),
    // Err(err) => {
    // Err(failed_to_parse_value(
    // &format!("{}: {}", key, value),
    // kt.1,
    // ))
    // },
    // }
    // }
  • replacement in src/lib.rs at line 211
    [3.954][3.954:1149]()
    Err(Error::new(ErrorKind::FromStr(
    format!("{}: {}", key, value),
    format!("{}", kt.1),
    )))
    [3.954]
    [3.1149]
    Err(failed_to_parse_value(
    &format!("{}: {}", key, value),
    kt.1,
    ))
  • replacement in src/lib.rs at line 218
    [3.23261][3.1191:1255]()
    _ => Err(Error::new(ErrorKind::EUniqueTokenFMany)),
    [3.23261]
    [3.23294]
    _ => Err(expected_unique_token_found_multi()),
  • replacement in src/lib.rs at line 236
    [3.23901][3.4302:4468](),[3.4468][3.24060:24132](),[3.24060][3.24060:24132](),[3.24132][3.4469:4556](),[3.4556][3.24225:24404](),[3.24225][3.24225:24404]()
    /// Coerces the value at key_path from a string to
    /// Some` of the receiver type, or None if there is
    /// nothing at key_path. See top page for example.
    pub fn op<T>(&self, key_path: &str) -> Result<Option<T>>
    where
    KeyTreeRef<'a>: TryInto<T>,
    KeyTreeRef<'a>: TryInto<T, Error = Error>,
    {
    let path = KeyPath::from_str(key_path);
    let kt = match self.op_recurse(&path)? {
    Some(kt) => kt,
    None => return Ok(None),
    };
    [3.23901]
    [3.24404]
    // /// Coerces the value at key_path from a string to
    // /// Some` of the receiver type, or None if there is
    // /// nothing at key_path. See top page for example.
    // pub fn op<T>(&self, key_path: &str) -> Result<Option<T>>
    // where
    // KeyTreeRef<'a>: TryInto<T>,
    // KeyTreeRef<'a>: TryInto<T, Error = Error>,
    // {
    // let path = KeyPath::from_str(key_path);
    // let kt = match self.op_recurse(&path)? {
    // Some(kt) => kt,
    // None => return Ok(None),
    // };
  • replacement in src/lib.rs at line 250
    [3.24405][3.4557:4600](),[3.4600][3.24447:24777](),[3.24447][3.24447:24777]()
    // Check that top token is unique.
    match kt.top_token().next() {
    None => {
    // re-wrap
    match kt.try_into() {
    Ok(t_item) => Ok(Some(t_item)),
    Err(e) => Err(e),
    }
    },
    _ => Err(Error::new(ErrorKind::EUniqueTokenFMany)),
    }
    }
    [3.24405]
    [3.24777]
    // // Check that top token is unique.
    // match kt.top_token().next() {
    // None => {
    // // re-wrap
    // match kt.try_into() {
    // Ok(t_item) => Ok(Some(t_item)),
    // Err(e) => Err(e),
    // }
    // },
    // _ => Err(expected_unique_token_found_multi()),
    // }
    // }
  • replacement in src/lib.rs at line 263
    [3.24778][3.24778:25026](),[3.25026][3.4601:4688](),[3.4688][3.25119:25243](),[3.25119][3.25119:25243]()
    /// Coerces the values at key_path from strings to a `Vec` of the receiver
    /// type, or an empty `Vec` if there is nothing at key_path. See top page
    /// for example.
    pub fn vec<T>(&self, key_path: &str) -> Result<Vec<T>>
    where
    KeyTreeRef<'a>: TryInto<T>,
    KeyTreeRef<'a>: TryInto<T, Error = Error>,
    {
    let path = KeyPath::from_str(key_path);
    match self.op_recurse(&path)? {
    Some(mut kt) => {
    [3.24778]
    [3.25243]
    // /// Coerces the values at key_path from strings to a `Vec` of the receiver
    // /// type, or an empty `Vec` if there is nothing at key_path. See top page
    // /// for example.
    // pub fn vec<T>(&self, key_path: &str) -> Result<Vec<T>>
    // where
    // KeyTreeRef<'a>: TryInto<T>,
    // KeyTreeRef<'a>: TryInto<T, Error = Error>,
    // {
    // let path = KeyPath::from_str(key_path);
    // match self.op_recurse(&path)? {
    // Some(mut kt) => {
  • replacement in src/lib.rs at line 275
    [3.25244][3.25244:25527]()
    let mut v = vec!(kt.clone().try_into()?);
    while let Some(_) = kt.next() {
    v.push(kt.clone().try_into()?);
    };
    Ok(v)
    },
    None => Ok(Vec::new()),
    }
    }
    [3.25244]
    [3.25527]
    // let mut v = vec!(kt.clone().try_into()?);
    //
    // while let Some(_) = kt.next() {
    // v.push(kt.clone().try_into()?);
    // };
    // Ok(v)
    // },
    // None => Ok(Vec::new()),
    // }
    // }
  • replacement in src/lib.rs at line 299
    [3.25941][3.25941:26192]()
    return Err(Error::new(ErrorKind::BadFirstSegment(
    self.top_token().to_string(),
    self.top_token().line().to_string(),
    path.to_string(),
    )))
    [3.25941]
    [3.26192]
    return Err(bad_first_segment(
    &self.top_token().to_string(),
    self.top_token().line(),
    &path.to_string(),
    ))
  • replacement in src/lib.rs at line 306
    [3.26225][3.26225:26295]()
    None => { return Err(Error::new(ErrorKind::EmptyPath)) },
    [3.26225]
    [3.26295]
    None => { return Err(empty_path()) },
  • replacement in src/lib.rs at line 313
    [3.26508][3.4790:4833](),[3.4833][2.1695:1758](),[2.1758][3.4882:4905](),[3.4882][3.4882:4905]()
    return Err(Error::new(
    ErrorKind::Expected_key_found_keyvalue
    ))
    [3.26508]
    [3.26577]
    return Err(
    expected_key_found_keyvalue()
    )
  • replacement in src/lib.rs at line 321
    [3.26783][3.4906:5212]()
    return Err(Error::new(
    ErrorKind::NoChildWithSegment(
    self.top_token().to_string(),
    self.top_token().line().to_string(),
    key.to_string(),
    [3.26783]
    [3.5212]
    return Err(
    no_child_with_segment(
    &self.top_token().to_string(),
    &self.top_token().line().to_string(),
    &key.to_string(),
  • replacement in src/lib.rs at line 327
    [3.5246][3.5246:5277]()
    ))
    [3.5246]
    [3.27076]
    )
  • replacement in src/lib.rs at line 336
    [3.27190][3.5278:5389](),[3.5389][3.27279:27411](),[3.27279][3.27279:27411](),[3.27411][3.5390:5449](),[3.5449][2.1759:1825](),[2.1825][3.5501:5557](),[3.5501][3.5501:5557](),[3.5557][3.27510:27593](),[3.27510][3.27510:27593]()
    pub (crate) fn op_recurse(
    &self,
    path: &KeyPath) -> Result<Option<KeyTreeRef<'a>>>
    {
    match self.recurse(path) {
    Ok(kt) => Ok(Some(kt)),
    Err(err) => {
    match err.kind() {
    ErrorKind::NoChildWithSegment(_, _, _)
    | ErrorKind::Expected_key_found_keyvalue => {
    Ok(None)
    },
    _ => Err(err),
    }
    }
    }
    }
    [3.27190]
    [3.27593]
    // pub (crate) fn op_recurse(
    // &self,
    // path: &KeyPath) -> Result<Option<KeyTreeRef<'a>>>
    // {
    // match self.recurse(path) {
    // Ok(kt) => Ok(Some(kt)),
    // Err(err) => {
    // match err.kind() {
    // ErrorKind::NoChildWithSegment(_, _, _)
    // | ErrorKind::Expected_key_found_keyvalue => {
    // Ok(None)
    // },
    // _ => Err(err),
    // }
    // }
    // }
    // }
  • replacement in src/into.rs at line 35
    [3.29609][3.29609:29647]()
    use crate::error::{Error, ErrorKind};
    [3.29609]
    [3.29647]
    use crate::error::Error;
    use crate::error::{
    expected_unique_found_multi,
    expected_keyvalue_found_key,
    failed_to_parse_value,
    };
  • replacement in src/into.rs at line 64
    [3.30129][2.1826:1949]()
    Some(i) => Err(Error::new(ErrorKind::Expected_unique_keyvalue_found_multi(String::from("todo"), *i))),
    [3.30129]
    [3.30210]
    Some(i) => Err(expected_unique_found_multi(&String::from("todo"), *i)),
  • replacement in src/into.rs at line 68
    [3.30331][3.1320:1387](),[3.1387][3.30404:30543](),[3.30404][3.30404:30543](),[3.30602][3.30602:30638]()
    Err(Error::new(ErrorKind::FromStr(
    self.top_token().to_string(),
    self.top_token().line().to_string(),
    )))
    [3.30331]
    [3.30638]
    Err(failed_to_parse_value(
    &self.top_token().to_string(),
    self.top_token().line(),
    ))
  • replacement in src/into.rs at line 78
    [3.30794][2.1950:2040]()
    Token::Key { .. } => Err(Error::new(ErrorKind::Expected_keyvalue_found_key)),
    [3.30794]
    [3.30870]
    Token::Key { .. } => Err(expected_keyvalue_found_key()),
  • replacement in src/error.rs at line 1
    [3.36577][3.36578:36664]()
    use std::error::Error as StdError;
    use std::fmt;
    use std::fmt::Display;
    use std::mem;
    [3.36577]
    [3.36664]
    // `Token` is passed as a string to 'cut' the reference.
  • replacement in src/error.rs at line 3
    [3.36665][3.36665:36682]()
    use crate::Line;
    [3.36665]
    [3.36682]
    // use std::error::Error as StdError;
    use std::fmt;
  • edit in src/error.rs at line 6
    [3.36893][3.36893:36917]()
    #[derive(Clone, Debug)]
  • edit in src/error.rs at line 8
    [3.665]
    [3.37048]
    // TODO: impl StdError;
  • replacement in src/error.rs at line 24
    [3.39074][2.2436:2509]()
    pub fn expected_unique_found_multi(token: &Token, pos: usize) -> Error {
    [3.39074]
    [2.2509]
    pub fn expected_unique_found_multi(token: &str, line: usize) -> Error {
  • replacement in src/error.rs at line 27
    [2.2537][2.2537:2642]()
    "[03] Line {}, token {}. Expected unique token but found multiple tokens.",
    pos,
    [2.2537]
    [2.2642]
    "[03] usize {}, token {}. Expected unique token but found multiple tokens.",
    line,
  • replacement in src/error.rs at line 40
    [3.43076][2.2837:2904]()
    pub fn failed_to_parse_value(token: &Token, pos: usize) -> Error {
    [3.43076]
    [2.2904]
    pub fn failed_to_parse_value(token: &str, line: usize) -> Error {
  • replacement in src/error.rs at line 43
    [2.2932][2.2932:3011]()
    "[05] Line {}, token {}. Failed to parse value.",
    pos,
    [2.2932]
    [2.3011]
    "[05] usize {}, token {}. Failed to parse value.",
    line,
  • replacement in src/error.rs at line 62
    [3.43585][2.3274:3345]()
    pub fn bad_indent(token: &Token, pos: usize, indent: usize) -> Error {
    [3.43585]
    [2.3345]
    pub fn bad_indent(token: &str, line: usize, indent: usize) -> Error {
  • replacement in src/error.rs at line 65
    [2.3373][2.3373:3444]()
    "[07] Line {}, token {}. Indentation of {} is incorrect.",
    [2.3373]
    [2.3444]
    "[07] usize {}, token {}. Indentation of {} is incorrect.",
  • replacement in src/error.rs at line 67
    [2.3462][2.3462:3479]()
    pos,
    [2.3462]
    [2.3479]
    token,
  • replacement in src/error.rs at line 78
    [3.43833][2.3601:3711]()
    pub fn first_token_must_be_key(token: &Token) -> Error {
    Error(String::from("First token must be [key:]."
    [3.43833]
    [2.3711]
    pub fn first_token_must_be_key(token: &str) -> Error {
    Error(String::from("First token must be [key:]."))
  • replacement in src/error.rs at line 82
    [3.43945][2.3714:3786]()
    pub fn incomplete_comment_or_key(token: &Token, line: usize) -> Error {
    [3.43945]
    [2.3786]
    pub fn incomplete_comment_or_key(token: &str, line: usize) -> Error {
  • replacement in src/error.rs at line 86
    [3.43946][2.3843:3905]()
    pub fn incomplete_line(token: &Token, line: usize) -> Error {
    [3.43946]
    [2.3905]
    pub fn incomplete_line(token: &str, line: usize) -> Error {
  • replacement in src/error.rs at line 90
    [3.44299][2.3952:4050]()
    pub fn no_colon_after_key(token: &Token) -> Error {
    Error(String::from("No colon after key.")
    [3.44299]
    [2.4050]
    pub fn no_colon_after_key(token: &str) -> Error {
    Error(String::from("No colon after key."))
  • replacement in src/error.rs at line 93
    [2.4052][3.44550:44551](),[3.44550][3.44550:44551](),[3.44551][2.4053:4136]()
    pub fn bad_first_segment(token: &Token, pos: usize, key_path: &KeyPath) -> Error {
    [2.4052]
    [2.4136]
    pub fn bad_first_segment(token: &str, line: usize, key_path: &str) -> Error {
  • edit in src/error.rs at line 99
    [3.45016]
    [2.4197]
    )
  • replacement in src/error.rs at line 102
    [3.351][2.4200:4270]()
    pub fn non_root_has_zero_indent(token: &Token line: usize) -> Error {
    [3.351]
    [2.4270]
    pub fn non_root_has_zero_indent(token: &str, line: usize) -> Error {