Scille/parsec-cloud

Better handling of missing block in `fd_read`

Opened this issue · 0 comments

see

ReadChunkOrBlockError::ChunkNotFound => anyhow::anyhow!(
"Chunk ID {} referenced in local manifest not in local storage !",
chunk_view.id

This can typically be triggered when the file manifest contains an invalid block ID (i.e. an ID that is not present in the local storage nor on the server side, as it could be the case with a buggy or malicious client having uploaded the manifest):

let data = super::fetch::fetch_block(
&self.cmds,
&self.certificates_ops,
self.realm_id,
remote_manifest,
access,
)
.await
.map_err(|err| match err {
FetchRemoteBlockError::Stopped => ReadChunkOrBlockError::Stopped,
FetchRemoteBlockError::Offline | FetchRemoteBlockError::StoreUnavailable => {
ReadChunkOrBlockError::Offline
}
FetchRemoteBlockError::BlockNotFound => ReadChunkOrBlockError::ChunkNotFound,

The panic is fine in itself ("chunk not found" refers to the fact we are in local referring to some non-existing data).
The issue comes from the fact we use this "chunk not found" error for something coming from the server, instead we should return a dedicated WorkspaceFdReadError::BlockNotFound error.