Skip to content

Commit 5120c63

Browse files
committed
improve: code cleanup
1 parent f5956ed commit 5120c63

File tree

5 files changed

+41
-39
lines changed

5 files changed

+41
-39
lines changed

crates/inferadb-engine-auth/src/signing_key_cache.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl SigningKeyCache {
337337
/// Non-transient errors (not found, serialization, internal) indicate a
338338
/// definitive response from Ledger and should not use fallback.
339339
fn is_transient_error(error: &StorageError) -> bool {
340-
matches!(error, StorageError::Connection(_) | StorageError::Timeout)
340+
matches!(error, StorageError::Connection { .. } | StorageError::Timeout { .. })
341341
}
342342

343343
/// Validates that a key is in a usable state.
@@ -742,11 +742,11 @@ mod tests {
742742
) -> Result<Option<PublicSigningKey>, StorageError> {
743743
if let Some(ref error) = *self.fail_with.lock().expect("lock") {
744744
return Err(match error {
745-
StorageError::Connection(msg) => StorageError::Connection(msg.clone()),
746-
StorageError::Timeout => StorageError::Timeout,
747-
StorageError::NotFound(msg) => StorageError::NotFound(msg.clone()),
748-
StorageError::Internal(msg) => StorageError::Internal(msg.clone()),
749-
_ => StorageError::Internal("unknown".to_string()),
745+
StorageError::Connection { message, .. } => StorageError::connection(message),
746+
StorageError::Timeout { .. } => StorageError::timeout(),
747+
StorageError::NotFound { key, .. } => StorageError::not_found(key),
748+
StorageError::Internal { message, .. } => StorageError::internal(message),
749+
_ => StorageError::internal("unknown"),
750750
});
751751
}
752752
self.inner.get_key(namespace_id, kid).await
@@ -797,7 +797,7 @@ mod tests {
797797
assert!(result1.is_ok());
798798

799799
// Simulate Ledger connection failure
800-
store.set_failure(Some(StorageError::Connection("network error".to_string())));
800+
store.set_failure(Some(StorageError::connection("network error")));
801801

802802
// Clear TTL cache to force Ledger lookup
803803
cache.clear_all().await;
@@ -824,7 +824,7 @@ mod tests {
824824
assert!(result1.is_ok());
825825

826826
// Simulate Ledger timeout
827-
store.set_failure(Some(StorageError::Timeout));
827+
store.set_failure(Some(StorageError::timeout()));
828828

829829
// Clear TTL cache
830830
cache.clear_all().await;
@@ -851,7 +851,7 @@ mod tests {
851851
assert!(result1.is_ok());
852852

853853
// Simulate non-transient internal error (should NOT use fallback)
854-
store.set_failure(Some(StorageError::Internal("db corruption".to_string())));
854+
store.set_failure(Some(StorageError::internal("db corruption")));
855855

856856
// Clear TTL cache
857857
cache.clear_all().await;
@@ -876,7 +876,7 @@ mod tests {
876876
);
877877

878878
// Simulate connection failure with no prior cache
879-
store.set_failure(Some(StorageError::Connection("network error".to_string())));
879+
store.set_failure(Some(StorageError::connection("network error")));
880880

881881
// Should return error since no fallback available
882882
let result = cache.get_decoding_key(1, "unknown-key").await;
@@ -888,25 +888,25 @@ mod tests {
888888

889889
#[test]
890890
fn test_is_transient_error_connection() {
891-
let error = StorageError::Connection("network error".to_string());
891+
let error = StorageError::connection("network error");
892892
assert!(is_transient_error(&error));
893893
}
894894

895895
#[test]
896896
fn test_is_transient_error_timeout() {
897-
let error = StorageError::Timeout;
897+
let error = StorageError::timeout();
898898
assert!(is_transient_error(&error));
899899
}
900900

901901
#[test]
902902
fn test_is_transient_error_not_found() {
903-
let error = StorageError::NotFound("key".to_string());
903+
let error = StorageError::not_found("key");
904904
assert!(!is_transient_error(&error));
905905
}
906906

907907
#[test]
908908
fn test_is_transient_error_internal() {
909-
let error = StorageError::Internal("oops".to_string());
909+
let error = StorageError::internal("oops");
910910
assert!(!is_transient_error(&error));
911911
}
912912

@@ -1062,7 +1062,7 @@ mod tests {
10621062
#[tokio::test]
10631063
async fn test_metrics_storage_error() {
10641064
let store = Arc::new(FailingStore::new());
1065-
store.set_failure(Some(StorageError::Internal("db error".to_string())));
1065+
store.set_failure(Some(StorageError::internal("db error")));
10661066

10671067
let metrics = create_test_metrics();
10681068
let cache = SigningKeyCache::new(

crates/inferadb-engine-auth/tests/signing_key_cache_ledger_integration.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -472,17 +472,19 @@ impl FailableStore {
472472
/// Reconstruct error since StorageError doesn't implement Clone
473473
fn reconstruct_error(error: &inferadb_storage::StorageError) -> inferadb_storage::StorageError {
474474
match error {
475-
inferadb_storage::StorageError::Connection(msg) => {
476-
inferadb_storage::StorageError::Connection(msg.clone())
475+
inferadb_storage::StorageError::Connection { message, .. } => {
476+
inferadb_storage::StorageError::connection(message)
477477
},
478-
inferadb_storage::StorageError::Timeout => inferadb_storage::StorageError::Timeout,
479-
inferadb_storage::StorageError::NotFound(msg) => {
480-
inferadb_storage::StorageError::NotFound(msg.clone())
478+
inferadb_storage::StorageError::Timeout { .. } => {
479+
inferadb_storage::StorageError::timeout()
481480
},
482-
inferadb_storage::StorageError::Internal(msg) => {
483-
inferadb_storage::StorageError::Internal(msg.clone())
481+
inferadb_storage::StorageError::NotFound { key, .. } => {
482+
inferadb_storage::StorageError::not_found(key)
484483
},
485-
_ => inferadb_storage::StorageError::Internal("unknown error type".to_string()),
484+
inferadb_storage::StorageError::Internal { message, .. } => {
485+
inferadb_storage::StorageError::internal(message)
486+
},
487+
_ => inferadb_storage::StorageError::internal("unknown error type"),
486488
}
487489
}
488490
}
@@ -604,9 +606,8 @@ async fn test_ledger_unavailability_fallback_integration() {
604606
cache.get_decoding_key(namespace_id, &kid).await.expect("initial fetch should succeed");
605607

606608
// Simulate Ledger becoming unavailable (connection error)
607-
failable_store.set_failure(Some(inferadb_storage::StorageError::Connection(
608-
"simulated network failure".to_string(),
609-
)));
609+
failable_store
610+
.set_failure(Some(inferadb_storage::StorageError::connection("simulated network failure")));
610611

611612
// Clear the TTL cache to force a "refetch" attempt
612613
cache.clear_all().await;
@@ -671,7 +672,7 @@ async fn test_ledger_timeout_fallback_integration() {
671672
let _ = cache.get_decoding_key(namespace_id, &kid).await.expect("initial fetch should succeed");
672673

673674
// Simulate timeout
674-
failable_store.set_failure(Some(inferadb_storage::StorageError::Timeout));
675+
failable_store.set_failure(Some(inferadb_storage::StorageError::timeout()));
675676

676677
// Clear TTL cache
677678
cache.clear_all().await;
@@ -720,9 +721,8 @@ async fn test_non_transient_error_no_fallback_integration() {
720721
let _ = cache.get_decoding_key(namespace_id, &kid).await.expect("initial fetch should succeed");
721722

722723
// Simulate internal error (non-transient)
723-
failable_store.set_failure(Some(inferadb_storage::StorageError::Internal(
724-
"database corruption".to_string(),
725-
)));
724+
failable_store
725+
.set_failure(Some(inferadb_storage::StorageError::internal("database corruption")));
726726

727727
// Clear TTL cache
728728
cache.clear_all().await;

crates/inferadb-engine-config/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,7 @@ impl Default for Config {
626626
token: TokenConfig::default(),
627627
pem: None,
628628
replication: ReplicationConfig::default(),
629+
schema: None,
629630
}
630631
}
631632
}

crates/inferadb-engine-config/src/validation.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,7 @@ mod tests {
242242
token: crate::TokenConfig::default(),
243243
pem: None,
244244
replication: crate::ReplicationConfig::default(),
245+
schema: None,
245246
};
246247

247248
match validate(&config) {

crates/inferadb-engine-repository/src/error.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ pub enum RepositoryError {
5252
impl From<StorageError> for RepositoryError {
5353
fn from(err: StorageError) -> Self {
5454
match err {
55-
StorageError::NotFound(key) => RepositoryError::NotFound(key),
56-
StorageError::Conflict => RepositoryError::Conflict,
57-
StorageError::Connection(msg) => RepositoryError::Connection(msg),
58-
StorageError::Serialization(msg) => RepositoryError::Serialization(msg),
59-
StorageError::Timeout => RepositoryError::Timeout,
60-
StorageError::Internal(msg) => RepositoryError::Internal(msg),
55+
StorageError::NotFound { key, .. } => RepositoryError::NotFound(key),
56+
StorageError::Conflict { .. } => RepositoryError::Conflict,
57+
StorageError::Connection { message, .. } => RepositoryError::Connection(message),
58+
StorageError::Serialization { message, .. } => RepositoryError::Serialization(message),
59+
StorageError::Timeout { .. } => RepositoryError::Timeout,
60+
StorageError::Internal { message, .. } => RepositoryError::Internal(message),
6161
}
6262
}
6363
}
@@ -68,15 +68,15 @@ mod tests {
6868

6969
#[test]
7070
fn test_storage_error_conversion() {
71-
let storage_err = StorageError::NotFound("test_key".to_string());
71+
let storage_err = StorageError::not_found("test_key");
7272
let repo_err: RepositoryError = storage_err.into();
7373
assert!(matches!(repo_err, RepositoryError::NotFound(_)));
7474

75-
let storage_err = StorageError::Conflict;
75+
let storage_err = StorageError::conflict();
7676
let repo_err: RepositoryError = storage_err.into();
7777
assert!(matches!(repo_err, RepositoryError::Conflict));
7878

79-
let storage_err = StorageError::Timeout;
79+
let storage_err = StorageError::timeout();
8080
let repo_err: RepositoryError = storage_err.into();
8181
assert!(matches!(repo_err, RepositoryError::Timeout));
8282
}

0 commit comments

Comments
 (0)