astmap-core 0.0.1

Core domain types and logic for astmap
Documentation
#[derive(Debug, thiserror::Error)]
pub enum DbError {
    #[error("database error: {0}")]
    Storage(String),
    #[error("database not found. Run 'astmap scan' first.")]
    NotFound,
    #[error("failed to create storage directory: {0}")]
    CreateDir(std::io::Error),
    #[error("format error: {0}")]
    Fmt(#[from] std::fmt::Error),
}

#[derive(Debug, thiserror::Error)]
pub enum DiffError {
    #[error("VCS error: {0}")]
    Vcs(String),
    #[error("database error: {0}")]
    Db(#[from] DbError),
    #[error("not a git repository")]
    NotGitRepo,
}

#[derive(Debug, thiserror::Error)]
pub enum ScanError {
    #[error("database error: {0}")]
    Db(#[from] DbError),
    #[error("IO error: {0}")]
    Io(#[from] std::io::Error),
    #[error("parser error: {0}")]
    Parse(String),
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_db_error_display() {
        let err = DbError::Storage("test error".to_string());
        assert_eq!(format!("{}", err), "database error: test error");

        let err = DbError::NotFound;
        assert!(format!("{}", err).contains("not found"));

        let io_err = std::io::Error::new(std::io::ErrorKind::PermissionDenied, "denied");
        let err = DbError::CreateDir(io_err);
        assert!(format!("{}", err).contains("denied"));
    }
}