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
// Copyright (c) Zefchain Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
/// Main error type for the crate.
#[derive(thiserror::Error, Debug)]
pub enum ViewError {
/// BCS serialization error.
#[error(transparent)]
BcsError(#[from] bcs::Error),
/// Input output error.
#[error("I/O error")]
IoError(#[from] std::io::Error),
/// Arithmetic error
#[error(transparent)]
ArithmeticError(#[from] linera_base::data_types::ArithmeticError),
/// Failed to lock a reentrant collection entry since it is currently being accessed
#[error(
"failed to lock a reentrant collection entry since it is currently being accessed: {0:?}"
)]
TryLockError(Vec<u8>),
/// Tokio errors can happen while joining.
#[error("panic in sub-task: {0}")]
TokioJoinError(#[from] tokio::task::JoinError),
/// Errors within the context can occur and are presented as `ViewError`.
#[error("storage operation error in {backend}: {error}")]
StoreError {
/// The name of the backend that produced the error
backend: &'static str,
/// The inner error
#[source]
error: Box<dyn std::error::Error + Send + Sync>,
/// Whether this error was caused by a journal resolution failure.
must_reload_view: bool,
},
/// The key must not be too long
#[error("the key must not be too long")]
KeyTooLong,
/// The entry does not exist in memory
// FIXME(#148): This belongs to a future `linera_storage::StoreError`.
#[error("entry does not exist in storage: {0}")]
NotFound(String),
/// The database is corrupt: Entries don't have the expected hash.
#[error("inconsistent database entries")]
InconsistentEntries,
/// The database is corrupt: Some entries are missing
#[error("missing database entries for the context {0}")]
MissingEntries(String),
/// The values are incoherent.
#[error("post load values error")]
PostLoadValuesError,
}
impl ViewError {
/// Returns `true` if this error was caused by a journal resolution failure,
/// which may leave storage in an inconsistent state requiring a view reload.
pub fn must_reload_view(&self) -> bool {
matches!(
self,
ViewError::StoreError {
must_reload_view: true,
..
}
)
}
}