Add better error messages for errors parsing and evaluating JS code (#1727)

* Add better error messages for errors parsing and evaluating JS code

* Grunt
This commit is contained in:
Winston Chang
2017-06-02 14:31:06 -05:00
committed by GitHub
parent 07ec7f8c13
commit 379d523ac5
6 changed files with 34 additions and 8 deletions

View File

@@ -11,6 +11,8 @@ shiny 1.0.3.9000
Addressed [#1501](https://github.com/rstudio/shiny/issues/1501): The `fileInput` control now retains uploaded file extensions on the server. This fixes [readxl](https://github.com/tidyverse/readxl)'s `readxl::read_excel` and other functions that must recognize a file's extension in order to work. ([#1706](https://github.com/rstudio/shiny/pull/1706))
For `conditionalPanel`s, Shiny now gives more informative messages if there are errors evaluating or parsing the JavaScript conditional expression. ([#1727](https://github.com/rstudio/shiny/pull/1727))
### Bug fixes
Fixed [#1701](https://github.com/rstudio/shiny/issues/1701): There was a partial argument match in the `generateOptions` function. ([#1702](https://github.com/rstudio/shiny/pull/1702))

View File

@@ -175,7 +175,14 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol
// "with" on the argument value, and return the result.
function scopeExprToFunc(expr) {
/*jshint evil: true */
var func = new Function("with (this) {return (" + expr + ");}");
var expr_escaped = expr.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
try {
var func = new Function('with (this) {\n try {\n return (' + expr + ');\n } catch (e) {\n console.error(\'Error evaluating expression: ' + expr_escaped + '\');\n throw e;\n }\n }');
} catch (e) {
console.error("Error parsing expression: " + expr);
throw e;
}
return function (scope) {
return func.call(scope);
};

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -161,7 +161,24 @@ function pixelRatio() {
// "with" on the argument value, and return the result.
function scopeExprToFunc(expr) {
/*jshint evil: true */
var func = new Function("with (this) {return (" + expr + ");}");
var expr_escaped = expr.replace(/[\\"']/g, '\\$&').replace(/\u0000/g, '\\0');
try {
var func = new Function(
`with (this) {
try {
return (${expr});
} catch (e) {
console.error('Error evaluating expression: ${expr_escaped}');
throw e;
}
}`
);
} catch (e) {
console.error("Error parsing expression: " + expr);
throw e;
}
return function(scope) {
return func.call(scope);
};