tweak the metadata line handler to handle an edge case in trim history
parent
6ae6445d95
commit
0d69620687
|
@ -211,12 +211,14 @@ Meta.createLineHandler = function (ref, errorHandler) {
|
|||
line: JSON.stringify(line),
|
||||
});
|
||||
}
|
||||
|
||||
// the case above is special, everything else should increment the index
|
||||
var index = ref.index++;
|
||||
if (typeof(line) === 'undefined') { return; }
|
||||
|
||||
if (Array.isArray(line)) {
|
||||
try {
|
||||
handleCommand(ref.meta, line);
|
||||
ref.index++;
|
||||
} catch (err2) {
|
||||
errorHandler("METADATA_COMMAND_ERR", {
|
||||
error: err2.stack,
|
||||
|
@ -226,8 +228,15 @@ Meta.createLineHandler = function (ref, errorHandler) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (ref.index === 0 && typeof(line) === 'object') {
|
||||
ref.index++;
|
||||
// the first line of a channel is processed before the dedicated metadata log.
|
||||
// it can contain a map, in which case it should be used as the initial state.
|
||||
// it's possible that a trim-history command was interrupted, in which case
|
||||
// this first message might exist in parallel with the more recent metadata log
|
||||
// which will contain the computed state of the previous metadata log
|
||||
// which has since been archived.
|
||||
// Thus, accept both the first and second lines you process as valid initial state
|
||||
// preferring the second if it exists
|
||||
if (index < 2 && line typeof(line) === 'object') {
|
||||
// special case!
|
||||
ref.meta = line;
|
||||
return;
|
||||
|
@ -235,7 +244,7 @@ Meta.createLineHandler = function (ref, errorHandler) {
|
|||
|
||||
errorHandler("METADATA_HANDLER_WEIRDLINE", {
|
||||
line: line,
|
||||
index: ref.index++,
|
||||
index: index,
|
||||
});
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue