mirror of
https://github.com/kanidm/kanidm.git
synced 2025-02-23 20:47:01 +01:00
Improve error handling
This commit is contained in:
parent
b729dc31c1
commit
16ca6f3116
|
@ -349,39 +349,41 @@ impl BackendWriteTransaction {
|
|||
entries: &Vec<Entry<EntryValid, EntryCommitted>>,
|
||||
) -> Result<(), BackendError> {
|
||||
// Perform a search for the entries --> This is a problem for the caller
|
||||
audit_segment!(au, || {
|
||||
|
||||
if entries.is_empty() {
|
||||
// TODO: Better error
|
||||
return Err(BackendError::EmptyRequest);
|
||||
}
|
||||
if entries.is_empty() {
|
||||
// TODO: Better error
|
||||
return Err(BackendError::EmptyRequest);
|
||||
}
|
||||
|
||||
// Assert the Id's exist on the entry.
|
||||
let id_list: Vec<i64> = entries.iter().filter_map(|entry| entry.id).collect();
|
||||
// Assert the Id's exist on the entry.
|
||||
let id_list: Vec<i64> = entries.iter().filter_map(|entry| entry.id).collect();
|
||||
|
||||
// Simple: If the list of id's is not the same as the input list, we are missing id's
|
||||
// TODO: This check won't be needed once I rebuild the entry state types.
|
||||
if entries.len() != id_list.len() {
|
||||
return Err(BackendError::EntryMissingId);
|
||||
}
|
||||
// Simple: If the list of id's is not the same as the input list, we are missing id's
|
||||
// TODO: This check won't be needed once I rebuild the entry state types.
|
||||
if entries.len() != id_list.len() {
|
||||
return Err(BackendError::EntryMissingId);
|
||||
}
|
||||
|
||||
// Now, given the list of id's, delete them.
|
||||
{
|
||||
// SQL doesn't say if the thing "does or does not exist anymore". As a result,
|
||||
// two deletes is a safe and valid operation. Given how we allocate ID's we are
|
||||
// probably okay with this.
|
||||
// Now, given the list of id's, delete them.
|
||||
{
|
||||
// SQL doesn't say if the thing "does or does not exist anymore". As a result,
|
||||
// two deletes is a safe and valid operation. Given how we allocate ID's we are
|
||||
// probably okay with this.
|
||||
|
||||
// TODO: ACTUALLY HANDLE THIS ERROR WILLIAM YOU LAZY SHIT.
|
||||
let mut stmt = self
|
||||
.conn
|
||||
.prepare("DELETE FROM id2entry WHERE id = :id")
|
||||
.unwrap();
|
||||
// TODO: ACTUALLY HANDLE THIS ERROR WILLIAM YOU LAZY SHIT.
|
||||
let mut stmt = self
|
||||
.conn
|
||||
.prepare("DELETE FROM id2entry WHERE id = :id")
|
||||
.unwrap();
|
||||
|
||||
id_list.iter().for_each(|id| {
|
||||
stmt.execute(&[id]).unwrap();
|
||||
});
|
||||
}
|
||||
id_list.iter().for_each(|id| {
|
||||
stmt.execute(&[id]).unwrap();
|
||||
});
|
||||
}
|
||||
|
||||
Ok(())
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn backup(&self) -> Result<(), BackendError> {
|
||||
|
@ -422,7 +424,7 @@ impl BackendWriteTransaction {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn setup(&self, audit: &mut AuditScope) -> Result<(), ()> {
|
||||
pub fn setup(&self, audit: &mut AuditScope) -> Result<(), OperationError> {
|
||||
{
|
||||
// self.conn.execute("BEGIN TRANSACTION", NO_PARAMS).unwrap();
|
||||
|
||||
|
@ -511,8 +513,10 @@ impl Backend {
|
|||
// Now complete our setup with a txn
|
||||
let r = {
|
||||
let be_txn = be.write();
|
||||
be_txn.setup(audit);
|
||||
be_txn.commit()
|
||||
be_txn.setup(audit)
|
||||
.and_then(|_| {
|
||||
be_txn.commit()
|
||||
})
|
||||
};
|
||||
|
||||
audit_log!(audit, "be new setup: {:?}", r);
|
||||
|
|
|
@ -124,7 +124,7 @@ impl Filter<FilterInvalid> {
|
|||
let attr_norm = schema_name.normalise_value(attr);
|
||||
// Now check it exists
|
||||
match schema_attributes.get(&attr_norm) {
|
||||
Some(schema_a) => {
|
||||
Some(_attr_name) => {
|
||||
// Return our valid data
|
||||
Ok(Filter::Pres(attr_norm))
|
||||
}
|
||||
|
|
|
@ -82,9 +82,11 @@ pub fn start(log: actix::Addr<EventLog>, path: &str, threads: usize) -> Result<a
|
|||
|
||||
let mut audit_qsc = AuditScope::new("query_server_init");
|
||||
let query_server_write = query_server.write();
|
||||
query_server_write.initialise(&mut audit_qsc);
|
||||
match query_server_write.initialise(&mut audit_qsc)
|
||||
.and_then(|_| {
|
||||
audit_segment!(audit_qsc, || query_server_write.commit(&mut audit_qsc))
|
||||
}) {
|
||||
// We are good to go! Finally commit and consume the txn.
|
||||
match audit_segment!(audit_qsc, || query_server_write.commit(&mut audit_qsc)) {
|
||||
Ok(_) => {}
|
||||
Err(e) => return Err(e),
|
||||
};
|
||||
|
@ -838,7 +840,7 @@ impl<'a> QueryServerWriteTransaction<'a> {
|
|||
audit_log!(audit, "Generated modlist -> {:?}", modlist);
|
||||
self.internal_modify(audit, filt, modlist)
|
||||
}
|
||||
Err(e) => {
|
||||
Err(_e) => {
|
||||
unimplemented!()
|
||||
// No action required.
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue