fix: Slightly better error passing to the client

This commit is contained in:
selfhoster selfhoster 2026-08-28 11:37:40 +02:00
commit a30e9c3dd9
3 changed files with 11 additions and 11 deletions

View file

@ -33,14 +33,12 @@ impl BasicLdapClient {
t t
} }
Ok(Err(err)) => { Ok(Err(err)) => {
// trace!(?addr, ?err, "error");
error!("error to {addr}: {err}"); error!("error to {addr}: {err}");
panic!(); return Err(LdapError::ConnectError);
} }
Err(_) => { Err(_) => {
warn!("timeout to {addr}"); warn!("timeout to {addr}");
panic!(); return Err(LdapError::Transport);
// continue;
} }
}; };
unixstream.into() unixstream.into()
@ -53,12 +51,11 @@ impl BasicLdapClient {
Ok(Err(err)) => { Ok(Err(err)) => {
// trace!(?addr, ?err, "error"); // trace!(?addr, ?err, "error");
error!("error to {addr}: {err}"); error!("error to {addr}: {err}");
panic!(); return Err(LdapError::ConnectError);
} }
Err(_) => { Err(_) => {
warn!("timeout to {addr}"); warn!("timeout to {addr}");
panic!(); return Err(LdapError::Transport);
// continue;
} }
}; };
tcpstream.into() tcpstream.into()

View file

@ -9,7 +9,9 @@ use std::sync::Arc;
use crate::{BasicLdapClient, ClientState, Config, Dn, LdapError}; use crate::{BasicLdapClient, ClientState, Config, Dn, LdapError};
pub fn bind_operror(msgid: i32, msg: &str) -> LdapMsg { // TODO: replace with a more generic approach for different op response types
// (bind, search) and custom error codes
pub fn bind_operror(msgid: i32, msg: &dyn ToString) -> LdapMsg {
LdapMsg { LdapMsg {
msgid, msgid,
op: LdapOp::BindResponse(LdapBindResponse { op: LdapOp::BindResponse(LdapBindResponse {
@ -97,7 +99,8 @@ pub async fn bind<W: AsyncWrite + Unpin>(
Ok(c) => c, Ok(c) => c,
Err(e) => { Err(e) => {
error!("A client build error has occurred: {e:?}"); error!("A client build error has occurred: {e:?}");
let resp_msg = bind_operror(msgid, "unable to bind"); // TODO: send more detailed error to the client (connection refused / timeout)
let resp_msg = bind_operror(msgid, &"unable to bind");
w.send(resp_msg).await.map_err(|err| { w.send(resp_msg).await.map_err(|err| {
error!("Unable to send response: {err}"); error!("Unable to send response: {err}");
LdapError::Transport LdapError::Transport
@ -125,7 +128,7 @@ pub async fn bind<W: AsyncWrite + Unpin>(
} }
Err(e) => { Err(e) => {
error!("A client bind error has occurred: {e:?}"); error!("A client bind error has occurred: {e:?}");
let resp_msg = bind_operror(msgid, "unable to bind"); let resp_msg = bind_operror(msgid, &"unable to bind");
w.send(resp_msg).await.map_err(|err| { w.send(resp_msg).await.map_err(|err| {
error!("Unable to send response: {err}"); error!("Unable to send response: {err}");
LdapError::Transport LdapError::Transport

View file

@ -30,7 +30,7 @@ pub async fn search<W: AsyncWrite + Unpin>(
Ok(data) => data, Ok(data) => data,
Err(e) => { Err(e) => {
error!("A client search error has occurred: {e:?}"); error!("A client search error has occurred: {e:?}");
let resp_msg = bind_operror(msgid, "unable to search"); let resp_msg = bind_operror(msgid, &"unable to search");
w.send(resp_msg).await.map_err(|err| { w.send(resp_msg).await.map_err(|err| {
error!("Unable to send response: {err}"); error!("Unable to send response: {err}");
LdapError::Transport LdapError::Transport