timestamp: Throw error if frontend cannot parse backend supplied time.

We have moved our invalid timestamp logic to use timestamp-error class,
however, if there are any valid outputs by the backend markdown that
the frontend considers invalid, we want to debug them. This commit
adds tooling to ensure we log those error messages.
This commit is contained in:
Rohitt Vashishtha 2020-07-06 20:47:31 +05:30 committed by Tim Abbott
parent 088b8e28c3
commit 1f765b41ce
2 changed files with 4 additions and 2 deletions

View File

@ -165,6 +165,7 @@ run_test('timestamp', () => {
const $timestamp_invalid = $.create('timestamp(invalid)');
$timestamp_invalid.attr('datetime', 'invalid');
$content.set_find_results('time', $array([$timestamp, $timestamp_invalid]));
blueslip.expect('error', 'Moment could not parse datetime supplied by backend: invalid');
// Initial asserts
assert.equal($timestamp.text(), 'never-been-set');
@ -175,7 +176,7 @@ run_test('timestamp', () => {
// Final asserts
assert.equal($timestamp.text(), 'Thu, Jan 1 1970, 12:00 AM');
assert.equal($timestamp.attr('title'), "This time is in your timezone. Original text was 'never-been-set'.");
assert.equal($timestamp_invalid.text(), 'translated: Could not parse timestamp.');
assert.equal($timestamp_invalid.text(), 'never-been-set');
});
run_test('timestamp-error', () => {

View File

@ -158,7 +158,8 @@ exports.update_elements = (content) => {
$(this).text(rendered_time.text);
$(this).attr('title', rendered_time.title);
} else {
$(this).text(i18n.t('Could not parse timestamp.'));
// This shouldn't happen. If it does, we're very interested in debugging it.
blueslip.error(`Moment could not parse datetime supplied by backend: ${time_str}`);
}
});