Return bank existence lookup errors to callers

- Make `bank_exists` surface backend/UID resolution failures instead of returning `false`
- Add SQF guard to log and alert on unexpected existence responses
- Prevent duplicate/default bank records after failed lookups
This commit is contained in:
Jacob Schmidt 2026-05-21 22:39:22 -05:00
parent 788ac6da7a
commit aad36ddd8d
2 changed files with 12 additions and 7 deletions

View File

@ -328,6 +328,11 @@ GVAR(BankBaseStore) = compileFinal createHashMapFromArray [
GVAR(BankMessenger) call ["sendAlert", [_uid, "error", _result select [7]]];
createHashMap
};
if !(_result in ["true", "false"]) exitWith {
["ERROR", format ["Bank exists check for %1 returned unexpected response: %2", _uid, _result]] call EFUNC(common,log);
GVAR(BankMessenger) call ["sendAlert", [_uid, "error", "Bank backend returned an unexpected existence response."]];
createHashMap
};
private _finalAccount = createHashMap;
private _wasCreated = false;

View File

@ -548,6 +548,8 @@ pub fn update_bank(call_context: CallContext, key: String, json_update: String)
/// Checks if an bank exists in the database.
///
/// Returns "true" if the bank exists, "false" otherwise.
/// Backend failures are returned as errors so callers do not confuse a failed
/// lookup with a missing account and create duplicate/default records.
pub fn bank_exists(call_context: CallContext, key: String) -> String {
log(
"bank",
@ -561,12 +563,9 @@ pub fn bank_exists(call_context: CallContext, key: String) -> String {
uid
}
None => {
log(
"bank",
"WARN",
&format!("Failed to resolve UID for key: {}", key),
);
return "false".to_string();
let error_msg = format!("Error: Failed to resolve UID for key: {}", key);
log("bank", "ERROR", &error_msg);
return error_msg;
}
};
@ -580,12 +579,13 @@ pub fn bank_exists(call_context: CallContext, key: String) -> String {
exists.to_string()
}
Err(e) => {
let error_msg = format!("Error: {}", e);
log(
"bank",
"ERROR",
&format!("Failed to check if bank '{}' exists: {}", resolved_uid, e),
);
"false".to_string()
error_msg
}
}
}