1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
//! Error handling for Sombra operations.
//!
//! This module defines the error types and handling utilities used
//! throughout the Sombra graph database. All public APIs return
//! `Result<T, GraphError>` for consistent error handling.
//!
//! # Error Types
//!
//! - [`GraphError`] - Main error enum with variants for different failure modes
//! - [`Result`] - Result type alias for convenience
//! - [`acquire_lock()`] - Helper for safe mutex locking
//!
//! # Error Handling Pattern
//!
//! ```rust
//! use sombra::{GraphDB, Result};
//!
//! fn safe_operation() -> Result<()> {
//! let mut db = GraphDB::open("test.db")?;
//! let mut tx = db.begin_transaction()?;
//! // ... operations ...
//! tx.commit()?;
//! Ok(())
//! }
//! ```
use io;
use ;
use Error;
use error;
/// Result type for Sombra operations.
///
/// All public APIs return `Result<T, GraphError>` for error handling.
pub type Result<T> = Result;
/// Errors that can occur during database operations.
///
/// Sombra uses this comprehensive error type to handle all failure modes
/// from I/O issues to data corruption to invalid usage.
/// Safely acquires a mutex lock with proper error handling.
///
/// This helper function handles mutex poisoning errors that can occur
/// when another thread panics while holding the lock. Instead of
/// panicking, it converts the error to a `GraphError::Corruption`.
///
/// # Arguments
/// * `mutex` - The mutex to lock
///
/// # Returns
/// A `MutexGuard` on success, or `GraphError::Corruption` if the lock is poisoned.
///
/// # Safety
/// This function is used throughout the codebase to ensure that lock
/// poisoning is handled gracefully rather than causing panics.