debugger icon indicating copy to clipboard operation
debugger copied to clipboard

Watch Expressions Shouldn't Be Allowed with Syntax Errors

Open darkwing opened this issue 9 years ago • 5 comments

I created a bogus watch expression:

watchsyntaxerror

If a syntax error is detected for a watch expression, we shouldn't allow its creation -- we should instead highlight the input box red and notify the user that their expression is invalid.

darkwing avatar Oct 29 '17 01:10 darkwing

The title was off based on your description.

wldcordeiro avatar Oct 29 '17 03:10 wldcordeiro

hmm. that's a good point... hadn't thought of that. That'll actually simplify the evaluate code a bit

jasonLaster avatar Oct 29 '17 18:10 jasonLaster

Here's a quick screenshot

in the future we can show a tooltip w/ the error, but that's not important now

and a patch

diff --git a/src/actions/expressions.js b/src/actions/expressions.js
index 85968ea..521e513 100644
--- a/src/actions/expressions.js
+++ b/src/actions/expressions.js
@@ -32,6 +32,11 @@ export function addExpression(input: string) {
       return;
     }
 
+    const error = await parser.hasSyntaxError(input);
+    if (error) {
+      return false;
+    }
+
     const expression = getExpression(getState(), input);
     if (expression) {
       return dispatch(evaluateExpression(expression));
@@ -102,14 +107,6 @@ function evaluateExpression(expression: Expression) {
     }
 
     let input = expression.input;
-    const error = await parser.hasSyntaxError(input);
-    if (error) {
-      return dispatch({
-        type: "EVALUATE_EXPRESSION",
-        input: expression.input,
-        value: { input: expression.input, result: error }
-      });
-    }
 
     const frame = getSelectedFrame(getState());
 
diff --git a/src/components/SecondaryPanes/Expressions.js b/src/components/SecondaryPanes/Expressions.js
index 5362c50..2a604f3 100644
--- a/src/components/SecondaryPanes/Expressions.js
+++ b/src/components/SecondaryPanes/Expressions.js
@@ -41,7 +41,8 @@ class Expressions extends PureComponent<Props, State> {
     super(...args);
 
     this.state = {
-      editing: null
+      editing: null,
+      error: null
     };
 
     this.renderExpression = this.renderExpression.bind(this);
@@ -163,26 +164,34 @@ class Expressions extends PureComponent<Props, State> {
     }
   }
 
-  renderNewExpressionInput() {
-    const onKeyPress = e => {
-      if (e.key !== "Enter") {
-        return;
-      }
-
-      const value = e.target.value;
-      if (value == "") {
-        return;
-      }
-
-      e.stopPropagation();
-      e.target.value = "";
-      this.props.addExpression(value);
-    };
+  onKeyPress = async e => {
+    if (e.key !== "Enter") {
+      return;
+    }
+
+    const value = e.target.value;
+    if (value == "") {
+      return;
+    }
 
+    e.stopPropagation();
+    const error = await parser.hasSyntaxError(value);
+    this.setState({ error });
+
+    if (error) {
+      return;
+    }
+
+    e.target.value = "";
+    this.props.addExpression(value);
+  };
+
+  renderNewExpressionInput() {
+    const {error} = state
     return (
       <li className="expression-input-container">
         <input
-          className="input-expression"
+          className=classnames("input-expression", {error})
           type="text"
           placeholder={L10N.getStr("expressions.placeholder")}
           onBlur={e => (e.target.value = "")}
diff --git a/src/components/SecondaryPanes/Frames/index.js b/src/components/SecondaryPanes/Frames/index.js
index d5d3b51..e98032b 100644
--- a/src/components/SecondaryPanes/Frames/index.js
+++ b/src/components/SecondaryPanes/Frames/index.js
@@ -204,6 +204,7 @@ class Frames extends Component<Props, State> {
   }
 }
 
+// Should be converted to flow types
 Frames.propTypes = {
   frames: PropTypes.array,
   frameworkGroupingOn: PropTypes.bool.isRequired,

jasonLaster avatar Nov 18 '17 20:11 jasonLaster

/claim

khal0988 avatar Nov 18 '17 21:11 khal0988

Thanks for claiming the issue! :wave:

Here are some links for getting setup, contributing, and developing. We're always happy to answer questions in slack! If you become busy, feel free to /unclaim it.

:fox_face: Debugger team!

claim avatar Nov 18 '17 21:11 claim