use a distinct error for out-of-sync replica
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use crate::settings::Settings;
|
||||
use taskchampion::{server::Server, Replica};
|
||||
use taskchampion::{server::Server, Error as TCError, Replica};
|
||||
use termcolor::WriteColor;
|
||||
|
||||
pub(crate) fn execute<W: WriteColor>(
|
||||
@@ -8,9 +8,32 @@ pub(crate) fn execute<W: WriteColor>(
|
||||
settings: &Settings,
|
||||
server: &mut Box<dyn Server>,
|
||||
) -> Result<(), crate::Error> {
|
||||
replica.sync(server, settings.avoid_snapshots)?;
|
||||
writeln!(w, "sync complete.")?;
|
||||
Ok(())
|
||||
match replica.sync(server, settings.avoid_snapshots) {
|
||||
Ok(()) => {
|
||||
writeln!(w, "sync complete.")?;
|
||||
Ok(())
|
||||
}
|
||||
Err(e) => match e.downcast() {
|
||||
Ok(TCError::OutOfSync) => {
|
||||
writeln!(w, "This replica cannot be synchronized with the server.")?;
|
||||
writeln!(
|
||||
w,
|
||||
"It may be too old, or some other failure may have occurred."
|
||||
)?;
|
||||
writeln!(
|
||||
w,
|
||||
"To start fresh, remove the local task database and run `ta sync` again."
|
||||
)?;
|
||||
writeln!(
|
||||
w,
|
||||
"Note that doing so will lose any un-synchronized local changes."
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
Ok(e) => Err(e.into()),
|
||||
Err(e) => Err(e.into()),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
Reference in New Issue
Block a user