You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Remove BlobsNotFound / EventsNotFound from the ViewError and make the read_blob / read_event return an option. (#4014)
## Motivation
The `ViewError` has the possibilities `BlobsNotFound` and
`EventsNotFound` which is a leakage of abstraction
as it should not be there.
## Proposal
There are several considerations for this work. The first is to
recognize that while the use of the `ViewError` to park
the error is inadequate, it is certainly practical.
**Possibility 1**: One possibility is to introduce a specific error
type:
```rust
enum StorageError {
BlobsNotFound(Vec<BlobId>),
EventsNotFound(Vec<EventId>),
ViewError(ViewError),
}
```
while this addresses the concern with `ViewError` it complexifies the
code significantly. Worse it presents another problem.
Suppose that a crate is using the `read_blob` but not the `read_event`.
Then it has to handle the possibility of an `EventsNotFound`. Of course
this could never materialize, but the type system implies that either it
is marked as unreachable, or an entry is added to the corresponding
error type.
**Possibility 2**: Add a `ReadBlobError` and a `ReadEventError`. This is
satisfying from the type system, though unwieldly.
**Possibility 3**: Replace the `read_blob` by `maybe_read_blob` and
return an Option. The caller is then responsible for handling the None
case and decide what to do in that case. This is the chosen solution.
It simplifies away quite some code but introduce some complicacies
elsewhere. This is preferable: The handling of missing case is the
responsibility of the caller.
**Note 1**: The same transformation is probably possible for
`read_blob_state(s)`. For `read_certificate(s)` this looks more
complicated and a `ReadCertificateError` might be the right solution
here. This should be handled in subsequent PR.
**Note 2**: The plural `BlobsNotFound` / `EventsNotFound` is kept.
However, an examination of the code shows that only singular are built.
Maybe there is an underlying issue to address.
Other points:
* The `BlobsNotFound` has been replaced from `ChainError` as it is never
built.
* The `read_network_description` has been changed into
`maybe_read_network_description` as an Option is returned.
## Test Plan
The CI.
## Release Plan
- Nothing to do / These changes follow the usual release cycle.
## Links
None.
0 commit comments