From 4d106b118ff496d07e17b28b37a4e3ec2c3580b7 Mon Sep 17 00:00:00 2001 From: Jathin Sreenivas Date: Fri, 26 Nov 2021 01:49:10 +0530 Subject: [PATCH] Templating exporter should have clear error reporting (#3945) * Templating exporter should have clear error reporting * Using i18n for meesage and removed the unnecessary null check * Removed usage of bindings * Adding tests for grel, renamed ParsetTests to TemplatingParserTests * Regex to test the keys of the template exporter * Cancel changes to the templating parser Co-authored-by: Antonin Delpeuch --- main/src/com/google/refine/grel/Parser.java | 4 +++- main/tests/server/src/com/google/refine/grel/GrelTests.java | 3 +++ main/webapp/modules/core/langs/translation-en.json | 1 + .../core/scripts/dialogs/templating-exporter-dialog.js | 6 +++++- 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/main/src/com/google/refine/grel/Parser.java b/main/src/com/google/refine/grel/Parser.java index bff82130b..b64c80f50 100644 --- a/main/src/com/google/refine/grel/Parser.java +++ b/main/src/com/google/refine/grel/Parser.java @@ -248,7 +248,9 @@ public class Parser { } while (_token != null) { - if (_token.type == TokenType.Operator && _token.text.equals(".")) { + if (_token.type == TokenType.Error) { + throw makeException("Unknown function or control named" + _token.text); + } else if (_token.type == TokenType.Operator && _token.text.equals(".")) { next(false); // swallow . if (_token == null || _token.type != TokenType.Identifier) { diff --git a/main/tests/server/src/com/google/refine/grel/GrelTests.java b/main/tests/server/src/com/google/refine/grel/GrelTests.java index d59c9b667..c74eceec5 100644 --- a/main/tests/server/src/com/google/refine/grel/GrelTests.java +++ b/main/tests/server/src/com/google/refine/grel/GrelTests.java @@ -82,6 +82,9 @@ public class GrelTests extends RefineTest { "", "1-1-", "2**3", + "value{datePart()", + "value}datePart()", + "value.datePart{}", // "2^3" // TODO: Should this generate an error? }; for (String test : tests) { diff --git a/main/webapp/modules/core/langs/translation-en.json b/main/webapp/modules/core/langs/translation-en.json index aa4597e82..d0171cc51 100644 --- a/main/webapp/modules/core/langs/translation-en.json +++ b/main/webapp/modules/core/langs/translation-en.json @@ -300,6 +300,7 @@ "core-dialogs/for-null-cell-value-to-empty-str-label": "Convert null value to NULL in INSERT", "core-dialogs/choose-export-destination": "Please choose the destination for project export", "core-dialogs/export-to-local": "OpenRefine project archive to file", + "core-dialogs/missing-bad-template": "Missing or bad template", "core-facets/remove-facet": "Remove this facet", "core-facets/minimize-facet": "Toggle between the minimization and maximization of this facet", "core-facets/reset": "reset", diff --git a/main/webapp/modules/core/scripts/dialogs/templating-exporter-dialog.js b/main/webapp/modules/core/scripts/dialogs/templating-exporter-dialog.js index 9910404a4..1c7c0a304 100644 --- a/main/webapp/modules/core/scripts/dialogs/templating-exporter-dialog.js +++ b/main/webapp/modules/core/scripts/dialogs/templating-exporter-dialog.js @@ -139,7 +139,11 @@ TemplatingExporterDialog.prototype._updatePreview = function() { self._elmts.previewTextarea[0].value = data; }, "text" - ); + ).fail(function (jqXhr, textStatus, errorMessage) { + if (jqXhr.status === 500) { + self._elmts.previewTextarea[0].value = $.i18n('core-dialogs/missing-bad-template'); + } + }); }; TemplatingExporterDialog.prototype._export = function() {