Skip to content

Commit

Permalink
Added thiserror to Error
Browse files Browse the repository at this point in the history
  • Loading branch information
keaz committed Nov 10, 2024
1 parent 839ea08 commit 2619d4a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 16 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ readme = "README.md"
repository = "https://github.com/keaz/simple-ldap"
keywords = ["ldap", "ldap3", "async", "high-level"]
name = "simple-ldap"
version = "2.0.0"
version = "2.1.0"
edition = "2021"


Expand All @@ -18,8 +18,9 @@ deadpool = "0.10.0"
futures = "0.3.31"
ldap3 = { version = "0.11.5", default-features = false }
log = "0.4.22"
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
serde = { version = "1.0.214", features = ["derive"] }
serde_json = "1.0.132"
thiserror = "2.0.2"

[features]
default = ["ldap3/default"]
Expand Down
38 changes: 25 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use ldap3::{
Ldap, LdapError, Mod, Scope, SearchEntry, SearchStream, StreamState,
};
use pool::Manager;
use thiserror::Error;

pub mod filter;
pub mod pool;
Expand Down Expand Up @@ -1439,36 +1440,47 @@ pub enum StreamResult<T> {
///
/// The error type for the LDAP client
///
#[derive(Debug)]
#[derive(Debug, Error)]
pub enum Error {
/// Error occured when performing a LDAP query
Query(String, LdapError),
#[error("{0}")]
Query(String, #[source] LdapError),
/// No records found for the search criteria
#[error("{0}")]
NotFound(String),
/// Multiple records found for the search criteria
#[error("{0}")]
MultipleResults(String),
/// Authentication failed
#[error("{0}")]
AuthenticationFailed(String),
/// Error occured when creating a record
Create(String, LdapError),
#[error("{0}")]
Create(String, #[source] LdapError),
/// Error occured when updating a record
Update(String, LdapError),
#[error("{0}")]
Update(String, #[source] LdapError),
/// Error occured when deleting a record
Delete(String, LdapError),
#[error("{0}")]
Delete(String, #[source] LdapError),
/// Error occured when mapping the search result to a struct
#[error("{0}")]
Mapping(String),
/// Error occurred while attempting to create a LDAP connection
Connection(String, LdapError),
#[error("{0}")]
Connection(String, #[source] LdapError),
/// Error occurred while using the connection pool
Pool(PoolError<LdapError>),
#[error("{0}")]
Pool(#[source] PoolError<LdapError>),
/// Error occurred while abandoning the search result
Abandon(String, LdapError),
#[error("{0}")]
Abandon(String, #[source] LdapError),
}

#[cfg(test)]
mod tests {

use filter::{ContainsFilter, LikeFilter, WildardOn};
use filter::ContainsFilter;
use futures::StreamExt;
use ldap3::tokio;
use serde::Deserialize;
Expand Down Expand Up @@ -1789,15 +1801,15 @@ mod tests {
while let Some(record) = result.next().await {
match record {
Ok(record) => {
let user = record.to_record::<User>().unwrap();
let _ = record.to_record::<User>().unwrap();
count += 1;
}
Err(_) => {
break;
}
}
}
result.cleanup().await;
let _ = result.cleanup().await;
assert!(count == 2);
}

Expand Down Expand Up @@ -1840,7 +1852,7 @@ mod tests {
}
}
assert!(count == 3);
result.cleanup().await;
let _ = result.cleanup().await;
}

#[tokio::test]
Expand Down Expand Up @@ -1882,7 +1894,7 @@ mod tests {
}
}
assert_eq!(count, 0);
result.cleanup().await;
let _ = result.cleanup().await;
}

#[tokio::test]
Expand Down

0 comments on commit 2619d4a

Please sign in to comment.