From 356f4e031c00461e6d40f3b8fad1b579b2e95760 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 00:24:46 +0800 Subject: [PATCH 1/7] Handle negative line numbers in error messages --- cider-eval.el | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index 2f0083e23..f9f10c4f9 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -568,8 +568,8 @@ It delegates the actual error content to the eval or op handler." " (")) (group-n 2 (minimal-match (zero-or-more anything))) ":" - (group-n 3 (one-or-more digit)) - (optional ":" (group-n 4 (one-or-more digit))) + (group-n 3 (one-or-more (any "-" digit))) ;; line numbers may be negative (#3687) + (optional ":" (group-n 4 (one-or-more (any "-" digit)))) ").")) (defconst cider-clojure-1.10-error (append `(sequence @@ -597,8 +597,8 @@ It delegates the actual error content to the eval or op handler." ", " (group-n 2 (minimal-match (zero-or-more anything))) ":" - (group-n 3 (one-or-more digit)) - (optional ":" (group-n 4 (one-or-more digit))) + (group-n 3 (one-or-more (any "-" digit))) + (optional ":" (group-n 4 (one-or-more (any "-" digit)))) " - ")) ;; Please keep this in sync with `cider-clojure-compilation-error-regexp', From a4d4c07c2ab1a37f0371655b0f835344b214a4e1 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 00:43:43 +0800 Subject: [PATCH 2/7] Use rx-to-string instead of eval, minor reformat --- cider-eval.el | 128 +++++++++++++++++++++++++------------------------- 1 file changed, 65 insertions(+), 63 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index f9f10c4f9..4645b9bb0 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -562,53 +562,55 @@ It delegates the actual error content to the eval or op handler." (t (cider-default-err-eval-print-handler)))) -(defconst cider-clojure-1.10--location `((or "at (" - (sequence "at " - (minimal-match (one-or-more anything)) ;; the fully-qualified name of the function that triggered the error - " (")) - (group-n 2 (minimal-match (zero-or-more anything))) - ":" - (group-n 3 (one-or-more (any "-" digit))) ;; line numbers may be negative (#3687) - (optional ":" (group-n 4 (one-or-more (any "-" digit)))) - ").")) - -(defconst cider-clojure-1.10-error (append `(sequence - "Syntax error " - (minimal-match (zero-or-more anything)) - (or "compiling " - "macroexpanding " - "reading source ") - (minimal-match (zero-or-more anything))) - cider-clojure-1.10--location)) - -(defconst cider-clojure-unexpected-error (append `(sequence - "Unexpected error (" - (minimal-match (one-or-more anything)) - ") " - (or "compiling " - "macroexpanding " - "reading source ") - (minimal-match (one-or-more anything))) - cider-clojure-1.10--location)) - -(defconst cider-clojure-warning `(sequence - (minimal-match (zero-or-more anything)) - (group-n 1 "warning") - ", " - (group-n 2 (minimal-match (zero-or-more anything))) - ":" - (group-n 3 (one-or-more (any "-" digit))) - (optional ":" (group-n 4 (one-or-more (any "-" digit)))) - " - ")) +(defconst cider-clojure-1.10--location + '(sequence + (or "at (" + (sequence "at " + (minimal-match (one-or-more anything)) ;; the fully-qualified name of the function that triggered the error + " (")) + (group-n 2 (minimal-match (zero-or-more anything))) ; source file + ":" (group-n 3 (one-or-more (any "-" digit))) ; line number, may be negative (#3687) + (optional + ":" (group-n 4 (one-or-more (any "-" digit)))) ; column number + ").")) + +(defconst cider-clojure-1.10-error + `(sequence + "Syntax error " + (minimal-match (zero-or-more anything)) + (or "compiling " + "macroexpanding " + "reading source ") + (minimal-match (zero-or-more anything)) + ,cider-clojure-1.10--location)) + +(defconst cider-clojure-unexpected-error + `(sequence + "Unexpected error (" (minimal-match (one-or-more anything)) ") " + (or "compiling " + "macroexpanding " + "reading source ") + (minimal-match (one-or-more anything)) + ,cider-clojure-1.10--location)) + +(defconst cider-clojure-warning + `(sequence + (minimal-match (zero-or-more anything)) + (group-n 1 "warning") + ", " (group-n 2 (minimal-match (zero-or-more anything))) + ":" (group-n 3 (one-or-more (any "-" digit))) + (optional + ":" (group-n 4 (one-or-more (any "-" digit)))) + " - ")) ;; Please keep this in sync with `cider-clojure-compilation-error-regexp', ;; which is a subset of these regexes. (defconst cider-clojure-compilation-regexp - (eval - `(rx bol (or ,cider-clojure-warning - ,cider-clojure-1.10-error - ,cider-clojure-unexpected-error)) - t) + (rx-to-string + `(seq bol (or ,cider-clojure-warning + ,cider-clojure-1.10-error + ,cider-clojure-unexpected-error)) + 'nogroup) "A few example values that will match: \"Reflection warning, /tmp/foo/src/foo/core.clj:14:1 - \" \"CompilerException java.lang.RuntimeException: Unable to resolve symbol: \\ @@ -617,10 +619,10 @@ lol in this context, compiling:(/foo/core.clj:10:1)\" \"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"") (defconst cider-clojure-compilation-error-regexp - (eval - `(rx bol (or ,cider-clojure-1.10-error - ,cider-clojure-unexpected-error)) - t) + (rx-to-string + `(seq bol (or ,cider-clojure-1.10-error + ,cider-clojure-unexpected-error)) + 'nogroup) "Like `cider-clojure-compilation-regexp', but excluding warnings such as reflection warnings. @@ -631,26 +633,26 @@ lol in this context, compiling:(/foo/core.clj:10:1)\" \"Unexpected error (ClassCastException) macroexpanding defmulti at (src/haystack/parser.cljc:21:1).\"") (defconst cider--clojure-execution-error-regexp - (append `(sequence - "Execution error " - (or (sequence "(" - (minimal-match (one-or-more anything)) - ")") - (minimal-match (zero-or-more anything)))) - cider-clojure-1.10--location)) + `(sequence + "Execution error " + (or (sequence "(" + (minimal-match (one-or-more anything)) + ")") + (minimal-match (zero-or-more anything))) + ,cider-clojure-1.10--location)) (defconst cider--clojure-spec-execution-error-regexp - (append `(sequence - "Execution error - invalid arguments to " - (minimal-match (one-or-more anything)) - " ") - cider-clojure-1.10--location)) + `(sequence + "Execution error - invalid arguments to " + (minimal-match (one-or-more anything)) + " " + ,cider-clojure-1.10--location)) (defconst cider-clojure-runtime-error-regexp - (eval - `(rx bol (or ,cider--clojure-execution-error-regexp - ,cider--clojure-spec-execution-error-regexp)) - t) + (rx-to-string + `(seq bol (or ,cider--clojure-execution-error-regexp + ,cider--clojure-spec-execution-error-regexp)) + 'nogroup) "Matches runtime errors, as oppsed to compile-time/macroexpansion-time errors. A few example values that will match: From 58ce929662d36a179a1ff910637d41646c26e762 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 00:44:34 +0800 Subject: [PATCH 3/7] Document semantics of match group numbering --- cider-eval.el | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index 4645b9bb0..31597a6a6 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -561,7 +561,7 @@ It delegates the actual error content to the eval or op handler." (cider-default-err-eval-handler)) (t (cider-default-err-eval-print-handler)))) - +;; See `cider-compilation-regexp' for interpretation of match groups. (defconst cider-clojure-1.10--location '(sequence (or "at (" @@ -676,7 +676,11 @@ A few example values that will match: ")")) (defvar cider-compilation-regexp - (list cider-clojure-compilation-regexp 2 3 4 '(1)) + (list cider-clojure-compilation-regexp + 2 ; FILE + 3 ; LINE + 4 ; COLUMN + '(1)) ; TYPE = (WARNING . INFO) "Specifications for matching errors and warnings in Clojure stacktraces. See `compilation-error-regexp-alist' for help on their format.") From 1378a72b3b9de7d6d11e5a54dc327f83a53b404b Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 00:52:00 +0800 Subject: [PATCH 4/7] Refactor an rx form --- cider-eval.el | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index 31597a6a6..366207a1b 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -564,10 +564,8 @@ It delegates the actual error content to the eval or op handler." ;; See `cider-compilation-regexp' for interpretation of match groups. (defconst cider-clojure-1.10--location '(sequence - (or "at (" - (sequence "at " - (minimal-match (one-or-more anything)) ;; the fully-qualified name of the function that triggered the error - " (")) + "at " (minimal-match (zero-or-more anything)) ;; the fully-qualified name of the function that triggered the error + "(" (group-n 2 (minimal-match (zero-or-more anything))) ; source file ":" (group-n 3 (one-or-more (any "-" digit))) ; line number, may be negative (#3687) (optional From de162d58c4fc452ea04cd0aef33593783980fef4 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 00:53:11 +0800 Subject: [PATCH 5/7] Redundant rx or clause (second clause always matches) --- cider-eval.el | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/cider-eval.el b/cider-eval.el index 366207a1b..16608ca43 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -633,10 +633,7 @@ lol in this context, compiling:(/foo/core.clj:10:1)\" (defconst cider--clojure-execution-error-regexp `(sequence "Execution error " - (or (sequence "(" - (minimal-match (one-or-more anything)) - ")") - (minimal-match (zero-or-more anything))) + (minimal-match (zero-or-more anything)) ,cider-clojure-1.10--location)) (defconst cider--clojure-spec-execution-error-regexp From 22c773168e928299c66bee3340f1c52be4451bc6 Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 01:04:42 +0800 Subject: [PATCH 6/7] Add test --- test/cider-error-parsing-tests.el | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/cider-error-parsing-tests.el b/test/cider-error-parsing-tests.el index 4a887ac47..8c01cd2c2 100644 --- a/test/cider-error-parsing-tests.el +++ b/test/cider-error-parsing-tests.el @@ -178,7 +178,16 @@ (expect (progn (string-match cider-clojure-runtime-error-regexp specimen) (match-string 2 specimen)) - :to-equal "src/haystack/parser.cljc")))) + :to-equal "src/haystack/parser.cljc"))) + + ;; Java source locations may be negative (#3687) + (it "Recognizes an error thrown from a java source file" + (let ((specimen "Execution error (FileNotFoundException) at java.io.FileInputStream/open0 (FileInputStream.java:-2).")) + (expect specimen :to-match cider-clojure-runtime-error-regexp) + (expect (progn + (string-match cider-clojure-runtime-error-regexp specimen) + (match-string 2 specimen)) + :to-equal "FileInputStream.java")))) (describe "cider-module-info-regexp" (it "Matches module info provided by Java" From 348dc156d87cc75719ffa4a19c6ae67909f265da Mon Sep 17 00:00:00 2001 From: yuhan0 Date: Thu, 30 May 2024 01:19:08 +0800 Subject: [PATCH 7/7] Add link to clojure source reference --- cider-eval.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cider-eval.el b/cider-eval.el index 16608ca43..bb88106aa 100644 --- a/cider-eval.el +++ b/cider-eval.el @@ -561,6 +561,8 @@ It delegates the actual error content to the eval or op handler." (cider-default-err-eval-handler)) (t (cider-default-err-eval-print-handler)))) +;; Reference: +;; https://github.com/clojure/clojure/blob/clojure-1.10.0/src/clj/clojure/main.clj#L251 ;; See `cider-compilation-regexp' for interpretation of match groups. (defconst cider-clojure-1.10--location '(sequence