Skip to content

Commit

Permalink
Add a string payload to RepoError::Incorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
alexjg committed Dec 12, 2023
1 parent 69b3ae7 commit 3ecdcdb
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub enum RepoError {
/// The repo is shutting down.
Shutdown,
/// Incorrect use of API. TODO: specify.
Incorrect,
Incorrect(String),
/// Error coming from storage.
StorageError(StorageError),
}
Expand Down Expand Up @@ -683,8 +683,12 @@ impl DocumentInfo {
let mut doc = self.document.write();
doc.automerge.load_incremental(&val)
};
if res.is_err() {
self.state.resolve_load_fut(Err(RepoError::Incorrect));
if let Err(e) = res {
self.state
.resolve_load_fut(Err(RepoError::Incorrect(format!(
"error loading document: {:?}",
e
))));
self.state = DocState::Error;
return;
}
Expand Down Expand Up @@ -720,8 +724,12 @@ impl DocumentInfo {
let mut doc = self.document.write();
doc.automerge.load_incremental(&val)
};
if res.is_err() {
self.state.resolve_bootstrap_fut(Err(RepoError::Incorrect));
if let Err(e) = res {
self.state
.resolve_bootstrap_fut(Err(RepoError::Incorrect(format!(
"error loading document: {:?}",
e
))));
self.state = DocState::Error;
return;
}
Expand Down Expand Up @@ -1334,7 +1342,8 @@ impl Repo {
);
info.state.resolve_bootstrap_fut(Ok(handle));
} else {
info.state.resolve_bootstrap_fut(Err(RepoError::Incorrect));
tracing::warn!(state=?info.state, "newdoc event received for existing document with incorrect state");
info.state.resolve_bootstrap_fut(Err(RepoError::Incorrect(format!("newdoc event received for existing document with incorrect state: {:?}", info.state))));
}
return;
} else {
Expand Down Expand Up @@ -1465,7 +1474,9 @@ impl Repo {
// If the doc is bootstrapping,
// the resolver could be added to the list of resolvers.
if !info.is_pending_load() {
resolver_clone.resolve_fut(Err(RepoError::Incorrect));
resolver_clone.resolve_fut(Err(RepoError::Incorrect(
"attempted to load a document which is already loading".to_string(),
)));
return;
}
info.poll_storage_operation(
Expand Down

0 comments on commit 3ecdcdb

Please sign in to comment.