Skip to content

Commit

Permalink
fixed schema validation and faulty regex (#561)
Browse files Browse the repository at this point in the history
* fixed schema validation and faulty regex

* fixed issues with persistent
  • Loading branch information
jsnoble authored and kstaken committed Sep 21, 2017
1 parent a096f1a commit 63071b2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
14 changes: 7 additions & 7 deletions lib/readers/elasticsearch_date_range/slicer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function newSlicer(context, opConfig, job, retryData, logger, client) {
function processInterval(str, esDates, opConfig) {
if (!moment(new Date(str)).isValid()) {
//one or more digits, followed by one or more letters, case-insensitive
var regex = /(\d+)([a-z]+)/i;
var regex = /(\d+)(\D+)/i;
var interval = regex.exec(str);

if (interval === null) {
Expand Down Expand Up @@ -377,7 +377,8 @@ function newSlicer(context, opConfig, job, retryData, logger, client) {
}

//make sure that end of last segment is always correct
results[results.length - 1].end = end.format(dateFormat);
const endingDate = end.format ? end.format(dateFormat) : moment(end).format(dateFormat);
results[results.length - 1].end = endingDate;

return results;
}
Expand Down Expand Up @@ -471,11 +472,10 @@ function newSlicer(context, opConfig, job, retryData, logger, client) {
count: data.count
}
}
}
.catch(function(err) {
return retryError(dateParams.start.format(dateFormat), err, sliceDate, msg)
})
);
})
.catch(function(err) {
return retryError(dateParams.start.format(dateFormat), err, sliceDate, msg)
});
}
};
}
Expand Down
5 changes: 4 additions & 1 deletion lib/readers/elasticsearch_reader.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,10 @@ function schema() {
default: 'auto',
format: function(val) {
if (val === 'auto') return;
dateOptions(val)
var regex = /(\d+)(\D+)/i;
var interval = regex.exec(val);
if (!interval) throw new Error('date interval is not formatted correctly');
dateOptions(interval[2]);
}
},
full_response: {
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/date_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function dateOptions(value) {
return options[value];
}
else {
throw new Error('date interval is not formatted correctly')
throw new Error('the time descriptor for the interval is malformed');
}
}

Expand Down

0 comments on commit 63071b2

Please sign in to comment.