Skip to content

Commit 870e287

Browse files
authored
linera-views: centralize the ViewError: From<Context::Error> bound into Context (#4029)
## Motivation We consistently require that the store errors be convertible to `ViewError`, but we don't encode that bound in `Context`, so we duplicate `ViewError: From<Context::Error>` bounds throughout the codebase. ## Proposal Move the bound into the definition of the `Context` trait instead. While we're at it, use a boxed error for the store errors in `ViewError` instead of converting to string, so that the backtrace and other error metadata isn't lost. ## Test Plan CI. ## Release Plan - Nothing to do / These changes follow the usual release cycle. ## Links - [reviewer checklist](https://github.com/linera-io/linera-protocol/blob/main/CONTRIBUTING.md#reviewer-checklist)
1 parent 57b8032 commit 870e287

File tree

86 files changed

+246
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+246
-359
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

linera-chain/src/inbox.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ use linera_views::{
1313
context::Context,
1414
queue_view::QueueView,
1515
register_view::RegisterView,
16-
views::{ClonableView, View, ViewError},
16+
views::{ClonableView, View},
17+
ViewError,
1718
};
1819
use serde::{Deserialize, Serialize};
1920
use thiserror::Error;

linera-chain/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use linera_base::{
3131
identifiers::{ApplicationId, ChainId},
3232
};
3333
use linera_execution::ExecutionError;
34-
use linera_views::views::ViewError;
34+
use linera_views::ViewError;
3535
use rand_distr::WeightedError;
3636
use thiserror::Error;
3737

linera-chain/src/manager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ use linera_views::{
8484
context::Context,
8585
map_view::MapView,
8686
register_view::RegisterView,
87-
views::{ClonableView, View, ViewError},
87+
views::{ClonableView, View},
88+
ViewError,
8889
};
8990
use rand_chacha::{rand_core::SeedableRng, ChaCha8Rng};
9091
use rand_distr::{Distribution, WeightedAliasIndex};

linera-chain/src/outbox.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ use linera_views::{
88
bucket_queue_view::BucketQueueView,
99
context::Context,
1010
register_view::RegisterView,
11-
views::{ClonableView, View, ViewError},
11+
views::{ClonableView, View},
12+
ViewError,
1213
};
1314

1415
#[cfg(test)]

linera-chain/src/pending_blobs.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ use linera_views::{
1212
context::Context,
1313
map_view::MapView,
1414
register_view::RegisterView,
15-
views::{ClonableView, View, ViewError},
15+
views::{ClonableView, View},
16+
ViewError,
1617
};
1718

1819
use crate::ChainError;

linera-chain/src/unit_tests/chain_tests.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use linera_execution::{
3232
use linera_views::{
3333
context::{Context as _, MemoryContext, ViewContext},
3434
memory::MemoryStore,
35-
views::{View, ViewError},
35+
views::View,
3636
};
3737
use test_case::test_case;
3838

@@ -43,13 +43,7 @@ use crate::{
4343
ChainError, ChainExecutionContext, ChainStateView,
4444
};
4545

46-
impl ChainStateView<MemoryContext<TestExecutionRuntimeContext>>
47-
where
48-
MemoryContext<TestExecutionRuntimeContext>:
49-
linera_views::context::Context + Clone + Send + Sync + 'static,
50-
ViewError:
51-
From<<MemoryContext<TestExecutionRuntimeContext> as linera_views::context::Context>::Error>,
52-
{
46+
impl ChainStateView<MemoryContext<TestExecutionRuntimeContext>> {
5347
pub async fn new(chain_id: ChainId) -> Self {
5448
let exec_runtime_context =
5549
TestExecutionRuntimeContext::new(chain_id, ExecutionRuntimeConfig::default());

linera-client/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) enum Inner {
2727
#[error("persistence error: {0}")]
2828
Persistence(#[source] Box<dyn std::error::Error + Send + Sync>),
2929
#[error("view error: {0}")]
30-
View(#[from] linera_views::views::ViewError),
30+
View(#[from] linera_views::ViewError),
3131
#[error("non-existent chain: {0:?}")]
3232
NonexistentChain(linera_base::identifiers::ChainId),
3333
#[error("no keypair found for chain: {0:?}")]

linera-core/src/chain_worker/state/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use linera_chain::{
2727
};
2828
use linera_execution::{ExecutionStateView, Query, QueryOutcome, ServiceRuntimeEndpoint};
2929
use linera_storage::{Clock as _, Storage};
30-
use linera_views::views::{ClonableView, ViewError};
30+
use linera_views::{views::ClonableView, ViewError};
3131
use tokio::sync::{oneshot, OwnedRwLockReadGuard, RwLock};
3232

3333
#[cfg(test)]

linera-core/src/client/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use linera_execution::{
6060
ExecutionError, Operation, Query, QueryOutcome, QueryResponse, SystemQuery, SystemResponse,
6161
};
6262
use linera_storage::{Clock as _, Storage as _};
63-
use linera_views::views::ViewError;
63+
use linera_views::ViewError;
6464
use rand::prelude::SliceRandom as _;
6565
use serde::{Deserialize, Serialize};
6666
use thiserror::Error;

0 commit comments

Comments
 (0)