Skip to content

Commit 99ea28e

Browse files
authored
Merge pull request share#506 from share/normalize-error
🥅 Catch `json0` normalization errors
2 parents 6d9afcb + e199a68 commit 99ea28e

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

lib/error.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ ShareDBError.CODES = {
3838
ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM: 'ERR_OP_VERSION_MISMATCH_AFTER_TRANSFORM',
3939
ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM: 'ERR_OP_VERSION_MISMATCH_DURING_TRANSFORM',
4040
ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT: 'ERR_OP_VERSION_NEWER_THAN_CURRENT_SNAPSHOT',
41+
ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED: 'ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED',
4142
ERR_OT_OP_BADLY_FORMED: 'ERR_OT_OP_BADLY_FORMED',
4243
ERR_OT_OP_NOT_APPLIED: 'ERR_OT_OP_NOT_APPLIED',
4344
ERR_OT_OP_NOT_PROVIDED: 'ERR_OT_OP_NOT_PROVIDED',

lib/ot.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,16 @@ exports.applyOps = function(snapshot, ops, options) {
164164
options = options || {};
165165
for (var index = 0; index < ops.length; index++) {
166166
var op = ops[index];
167-
if (options._normalizeLegacyJson0Ops) normalizeLegacyJson0Ops(snapshot, op);
167+
if (options._normalizeLegacyJson0Ops) {
168+
try {
169+
normalizeLegacyJson0Ops(snapshot, op);
170+
} catch (error) {
171+
return new ShareDBError(
172+
ERROR_CODE.ERR_OT_LEGACY_JSON0_OP_CANNOT_BE_NORMALIZED,
173+
'Cannot normalize legacy json0 op'
174+
);
175+
}
176+
}
168177
snapshot.v = op.v;
169178
var error = exports.apply(snapshot, op);
170179
if (error) return error;

0 commit comments

Comments
 (0)