Coverage Report

Created: 2026-03-23 07:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/surrealmx-0.18.0/src/err.rs
Line
Count
Source
1
// Copyright © SurrealDB Ltd
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//     http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
//! This module stores the database error types.
16
17
use bincode::error::DecodeError as BincodeDecodeError;
18
use bincode::error::EncodeError as BincodeEncodeError;
19
use std::io::Error as IoError;
20
use std::sync::PoisonError;
21
use thiserror::Error;
22
23
/// The errors which can be emitted from a database.
24
#[derive(Error, Debug)]
25
pub enum Error {
26
  /// A transaction is closed.
27
  #[error("Transaction is closed")]
28
  TxClosed,
29
30
  /// A transaction is not writable.
31
  #[error("Transaction is not writable")]
32
  TxNotWritable,
33
34
  /// A key being inserted already exists.
35
  #[error("Key being inserted already exists")]
36
  KeyAlreadyExists,
37
38
  /// A value being checked was not correct.
39
  #[error("Value being checked was not correct")]
40
  ValNotExpectedValue,
41
42
  /// A read conflict, retry the transaction.
43
  #[error("Read conflict, retry the transaction")]
44
  KeyReadConflict,
45
46
  /// A write conflict, retry the transaction.
47
  #[error("Write conflict, retry the transaction")]
48
  KeyWriteConflict,
49
50
  /// Can not fetch value at a future version.
51
  #[error("Can not fetch value at a future version")]
52
  VersionInFuture,
53
54
  /// No savepoint has been set.
55
  #[error("No savepoint has been set")]
56
  NoSavepoint,
57
58
  /// A transaction is not persistent.
59
  #[error("Transaction is not persistent")]
60
  TxCommitNotPersisted(PersistenceError),
61
}
62
63
/// The errors that can occur during persistence operations.
64
#[derive(Error, Debug)]
65
pub enum PersistenceError {
66
  /// An IO error occurred.
67
  #[error("IO error: {0}")]
68
  Io(#[from] IoError),
69
70
  /// A serialization error occurred.
71
  #[error("Serialization error: {0}")]
72
  Serialization(#[from] BincodeEncodeError),
73
74
  /// A deserialization error occurred.
75
  #[error("Deserialization error: {0}")]
76
  Deserialization(#[from] BincodeDecodeError),
77
78
  /// A lock acquisition failed.
79
  #[error("Lock acquisition failed")]
80
  LockFailed(String),
81
82
  /// A snapshot creation failed.
83
  #[error("Snapshot creation failed: {0}")]
84
  SnapshotFailed(String),
85
86
  /// An AOL append failed.
87
  #[error("AOL append failed: {0}")]
88
  AppendFailed(String),
89
}
90
91
impl<T> From<PoisonError<std::sync::MutexGuard<'_, T>>> for PersistenceError {
92
0
  fn from(error: PoisonError<std::sync::MutexGuard<'_, T>>) -> Self {
93
0
    PersistenceError::LockFailed(error.to_string())
94
0
  }
Unexecuted instantiation: <surrealmx::err::PersistenceError as core::convert::From<std::sync::poison::PoisonError<std::sync::poison::mutex::MutexGuard<std::fs::File>>>>::from
Unexecuted instantiation: <surrealmx::err::PersistenceError as core::convert::From<std::sync::poison::PoisonError<std::sync::poison::mutex::MutexGuard<std::time::Instant>>>>::from
95
}