Repository: KaTeX/KaTeX (js)

Issue:
\right{...} causes circular structure in error reporting
**Describe the bug:**
Testing on `katex.org`, here is a minimal bad example based on #2174:
```latex
\newcommand{\myright}[1]{\right{#1}}
\cos\left(x\myright)
```
Error:
> Converting circular structure to JSON --> starting at object with constructor 't' | property 'settings' -> object with constructor 't' | property 'macros' -> object with constructor 'Object' | ... | property 'loc' -> object with constructor 't' --- property 'lexer' closes the circle

**Expected behavior:**
Unless I'm missing something, `\myright` should behave like `\right`.

**Additional context:**
The following code works fine, so it has to do with macro arguments.
```latex
\newcommand{\myright}{\right}
\cos\left(x\myright)
```
Perhaps #2085 fixes this bug, but I haven't checked. If so, we should add a test.

Pull request description:
Fix delimiter error message
Avoid "circular structure" error message by avoiding `JSON.stringify` on a parse structure when getting an invalid delimiter type (e.g. ordgroup). Instead, report type of delimiter when it's invalid.  Fixes #2184.

Patch:
diff --git a/src/functions/delimsizing.js b/src/functions/delimsizing.js
index 25c26017..f1fdd0af 100644
--- a/src/functions/delimsizing.js
+++ b/src/functions/delimsizing.js
@@ -62,11 +62,12 @@ function checkDelimiter(
     const symDelim = checkSymbolNodeType(delim);
     if (symDelim && utils.contains(delimiters, symDelim.text)) {
         return symDelim;
-    } else {
+    } else if (symDelim) {
         throw new ParseError(
-            "Invalid delimiter: '" +
-            (symDelim ? symDelim.text : JSON.stringify(delim)) +
-            "' after '" + context.funcName + "'", delim);
+            `Invalid delimiter '${symDelim.text}' after '${context.funcName}'`,
+            delim);
+    } else {
+        throw new ParseError(`Invalid delimiter type '${delim.type}'`, delim);
     }
 }
 


Test patch:
diff --git a/test/errors-spec.js b/test/errors-spec.js
index 70aea787..42c04abd 100644
--- a/test/errors-spec.js
+++ b/test/errors-spec.js
@@ -250,14 +250,24 @@ describe("functions.js:", function() {
     describe("delimiter functions", function() {
         it("reject invalid opening delimiters", function() {
             expect`\bigl 1 + 2 \bigr`.toFailWithParseError(
-                   "Invalid delimiter: '1' after '\\bigl' at position 7:" +
+                   "Invalid delimiter '1' after '\\bigl' at position 7:" +
                    " \\bigl 1̲ + 2 \\bigr");
         });
         it("reject invalid closing delimiters", function() {
             expect`\bigl(1+2\bigr=3`.toFailWithParseError(
-                   "Invalid delimiter: '=' after '\\bigr' at position 15:" +
+                   "Invalid delimiter '=' after '\\bigr' at position 15:" +
                    " \\bigl(1+2\\bigr=̲3");
         });
+        it("reject group opening delimiters", function() {
+            expect`\bigl{(}1+2\bigr)3`.toFailWithParseError(
+                   "Invalid delimiter type 'ordgroup' at position 6:" +
+                   " \\bigl{̲(̲}̲1+2\\bigr)3");
+        });
+        it("reject group closing delimiters", function() {
+            expect`\bigl(1+2\bigr{)}3`.toFailWithParseError(
+                   "Invalid delimiter type 'ordgroup' at position 15:" +
+                   " \\bigl(1+2\\bigr{̲)̲}̲3");
+        });
     });
 
     describe("\\begin and \\end", function() {