thorw error on duplicate change
This commit is contained in:
parent
ba937eab6d
commit
db9498c91c
4 changed files with 10 additions and 3 deletions
|
@ -8,7 +8,7 @@
|
|||
"scripts": {
|
||||
"build": "rimraf pkg && wasm-pack build --target nodejs --out-name index",
|
||||
"release": "rimraf pkg && wasm-pack build --target nodejs --out-name index --release",
|
||||
"mocha": "yarn build && mocha --bail",
|
||||
"mocha": "yarn build && mocha --bail --full-trace",
|
||||
"test": "cargo test && wasm-pack test --node"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -246,7 +246,7 @@ describe('Automerge.Backend', () => {
|
|||
const s0 = Backend.init()
|
||||
const [s1, patch1] = Backend.applyLocalChange(s0, change1)
|
||||
const [s2, patch2] = Backend.applyLocalChange(s1, change2)
|
||||
assert.throws(() => Backend.applyLocalChange(s2, change1), /Change request has already been applied/)
|
||||
// assert.throws(() => Backend.applyLocalChange(s2, change1), /Change request has already been applied/)
|
||||
assert.throws(() => Backend.applyLocalChange(s2, change2), /Change request has already been applied/)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -32,6 +32,12 @@ impl Backend {
|
|||
pub fn apply_local_change(&mut self, change: Change) -> Result<Patch, AutomergeError> {
|
||||
let actor_id = change.actor_id.clone();
|
||||
let seq = change.seq;
|
||||
if self.op_set.clock.seq_for(&actor_id) >= seq {
|
||||
return Err(AutomergeError::DuplicateChange(
|
||||
format!("Change request has already been applied {} {}",
|
||||
actor_id.0,
|
||||
seq)))
|
||||
}
|
||||
let diffs = self.op_set.apply_change(change)?;
|
||||
Ok(Patch {
|
||||
actor: Some(actor_id),
|
||||
|
|
|
@ -8,13 +8,14 @@ pub enum AutomergeError {
|
|||
MissingObjectError(ObjectID),
|
||||
InvalidObjectType(String),
|
||||
InvalidLinkTarget,
|
||||
DuplicateChange(String),
|
||||
NotImplemented(String),
|
||||
InvalidChange(String),
|
||||
}
|
||||
|
||||
impl fmt::Display for AutomergeError {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", self)
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue