mirror of
https://github.com/ether/etherpad-lite.git
synced 2025-01-19 14:13:34 +01:00
PadMessageHandler: Factor out common USER_CHANGES error message formatting
This commit is contained in:
parent
35b2aeb3b1
commit
1447ab8899
1 changed files with 46 additions and 55 deletions
|
@ -600,7 +600,6 @@ const handleUserChanges = async (socket, message) => {
|
|||
const pad = await padManager.getPad(thisSession.padId);
|
||||
|
||||
// create the changeset
|
||||
try {
|
||||
try {
|
||||
// Verify that the changeset has valid syntax and is in canonical form
|
||||
Changeset.checkRep(changeset);
|
||||
|
@ -644,9 +643,6 @@ const handleUserChanges = async (socket, message) => {
|
|||
|
||||
// Afaik, it copies the new attributes from the changeset, to the global Attribute Pool
|
||||
changeset = Changeset.moveOpsToNewPool(changeset, wireApool, pad.pool);
|
||||
} catch (e) {
|
||||
throw new Error(`Can't apply USER_CHANGES from Socket ${socket.id} because: ${e.message}`);
|
||||
}
|
||||
|
||||
// ex. applyUserChanges
|
||||
const apool = pad.pool;
|
||||
|
@ -665,24 +661,18 @@ const handleUserChanges = async (socket, message) => {
|
|||
// rebases "changeset" so that it is relative to revision r
|
||||
// and can be applied after "c".
|
||||
|
||||
try {
|
||||
// a changeset can be based on an old revision with the same changes in it
|
||||
// prevent eplite from accepting it TODO: better send the client a NEW_CHANGES
|
||||
// of that revision
|
||||
if (baseRev + 1 === r && c === changeset) {
|
||||
throw new Error("Won't apply USER_CHANGES, as it contains an already accepted changeset");
|
||||
}
|
||||
if (baseRev + 1 === r && c === changeset) throw new Error('Changeset already accepted');
|
||||
|
||||
changeset = Changeset.follow(c, changeset, false, apool);
|
||||
} catch (e) {
|
||||
throw new Error(`Can't apply USER_CHANGES, because ${e.message}`);
|
||||
}
|
||||
}
|
||||
|
||||
const prevText = pad.text();
|
||||
|
||||
if (Changeset.oldLen(changeset) !== prevText.length) {
|
||||
throw new Error(`Can't apply USER_CHANGES ${changeset} with oldLen ` +
|
||||
throw new Error(`Can't apply changeset ${changeset} with oldLen ` +
|
||||
`${Changeset.oldLen(changeset)} to document of length ${prevText.length}`);
|
||||
}
|
||||
|
||||
|
@ -703,7 +693,8 @@ const handleUserChanges = async (socket, message) => {
|
|||
} catch (err) {
|
||||
socket.json.send({disconnect: 'badChangeset'});
|
||||
stats.meter('failedChangesets').mark();
|
||||
console.warn(err.stack || err);
|
||||
console.warn(`Failed to apply USER_CHANGES from author ${thisSession.author} ` +
|
||||
`(socket ${socket.id}) on pad ${thisSession.padId}: ${err.stack || err}`);
|
||||
}
|
||||
|
||||
stopWatch.end();
|
||||
|
|
Loading…
Reference in a new issue