[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/bug-hunter 98e0362 32/95: Recognize errors at reader le
From: |
Stefan Monnier |
Subject: |
[elpa] externals/bug-hunter 98e0362 32/95: Recognize errors at reader level. |
Date: |
Fri, 27 Nov 2020 22:06:51 -0500 (EST) |
branch: externals/bug-hunter
commit 98e036270a5363dc996c044fad47251f8c1879c7
Author: Artur Malabarba <bruce.connor.am@gmail.com>
Commit: Artur Malabarba <bruce.connor.am@gmail.com>
Recognize errors at reader level.
---
bug-hunter.el | 53 ++++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 42 insertions(+), 11 deletions(-)
diff --git a/bug-hunter.el b/bug-hunter.el
index 77b74b5..05f3ad1 100644
--- a/bug-hunter.el
+++ b/bug-hunter.el
@@ -6,7 +6,7 @@
;; URL: http://github.com/Bruce-Connor/elisp-bug-hunter
;; Version: 0.1
;; Keywords: lisp
-;; Package-Requires: ((seq "1.3"))
+;; Package-Requires: ((seq "1.3") (cl-lib "0.5"))
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
@@ -59,14 +59,25 @@
;;; Code:
(require 'seq)
+(require 'cl-lib)
(defun bug-hunter--read-buffer ()
"Return all sexps after point as a list."
- (let ((out))
- (ignore-errors
- (while t
- (push (read (current-buffer)) out)))
- (nreverse out)))
+ (let ((out)
+ (line))
+ (or (condition-case er
+ ;; Looks hacky, but comes from `byte-compile-from-buffer'.
+ (while (progn (while (progn (skip-chars-forward " \t\n\^l")
+ (looking-at ";"))
+ (forward-line 1))
+ (not (eobp)))
+ (setq line (line-number-at-pos (point)))
+ (push (read (current-buffer)) out)
+ nil)
+ (end-of-file `(bug-caught ,line end-of-file))
+ (invalid-read-syntax `(bug-caught ,line ,@er))
+ (error (error "Ran into an error we don't understand, please file a
bug report: %S" er)))
+ (nreverse out))))
(defun bug-hunter--read-contents (file)
"Return all sexps in FILE as a list."
@@ -125,7 +136,7 @@ See `bug-hunter' for a description on the ASSERTION."
(progn ,@forms
(run-hooks 'after-init-hook)
,assertion)
- (error (cons 'error er)))))
+ (error (cons 'bug-caught er)))))
(defun bug-hunter--init-report-buffer ()
(or (get-buffer "*Bug-Hunter Report*")
@@ -150,7 +161,7 @@ See `bug-hunter' for a description on the ASSERTION."
;; easier to just run it anyway to get the return value.
(bug-hunter--run-and-test (append safe head) assertion)))
((and (message "Testing: %s/%s"
- (setq bug-hunter--i (1+ bug-hunter--i))
+ (cl-incf bug-hunter--i)
bug-hunter--estimate)
(bug-hunter--run-and-test (append safe head) assertion))
(apply #'bug-hunter--bisect
@@ -169,11 +180,29 @@ element in FORMS which trigger ASSERTION, and value is the
ASSERTION's return value.
If ASSERTION is nil, n is the position of the first form to
-signal an error and value is (error . ERROR-SIGNALED)."
+signal an error and value is (bug-caught . ERROR-SIGNALED)."
(let ((bug-hunter--i 0)
(bug-hunter--estimate (ceiling (log (length forms) 2))))
(apply #'bug-hunter--bisect assertion nil (bug-hunter--split forms))))
+(defun bug-hunter--report-error (line error-description &optional info)
+ (apply #'bug-hunter--report-end
+ (cl-case error-description
+ (end-of-file
+ (list "There's a missing closing parenthesis, %s%s%s"
+ "the expression on line " line " never ends"))
+ (invalid-read-syntax
+ (if (member info '("]" ")"))
+ (list "There's an extra %s on line %s%s%s%s" info
+ line ". There's probably a missing "
+ (if (string= info ")") "(" "[")
+ " before that.")
+ (list "There's a %s on line %s, and that is not valid elisp syntax."
+ info line
+ ", maybe there is a missing opening parenthesis before that.")))
+ (t (list "Found the following error on line %s: %S"
+ line (cons error-description info))))))
+
;;; Main functions
(defun bug-hunter-hunt (forms assertion)
@@ -192,7 +221,9 @@ Make sure that ASSERTION does not throw errors when all is
well (check against emacs -Q).
One common source of that is to rely on a feature being loaded."
(pop-to-buffer (bug-hunter--init-report-buffer))
- (bug-hunter--report "Testing assertion...")
+ (when (eq (car-safe forms) 'bug-caught)
+ (apply #'bug-hunter--report-error (cdr forms)))
+ (bug-hunter--report "Doing some initial tests...")
(unless (bug-hunter--run-and-test forms assertion)
(bug-hunter--report-end "Test failed.\n%s\n%s"
(if assertion "Assertion returned nil even with all forms evaluated:"
@@ -213,7 +244,7 @@ One common source of that is to rely on a feature being
loaded."
(bug-hunter--report "Bug encountered on the following sexp at position
%s:\n %S"
pos
(elt forms pos))
- (if (eq (car-safe ret) 'error)
+ (if (eq (car-safe ret) 'bug-caught)
(bug-hunter--report "The following error was signaled: %s\n" (cdr
ret))
(bug-hunter--report "The return value was: %s\n" ret))
result))))
- [elpa] externals/bug-hunter 2caf570 15/95: Fix tests, (continued)
- [elpa] externals/bug-hunter 2caf570 15/95: Fix tests, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 45bbc36 20/95: Readme link, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 9be6176 21/95: Readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 7594b29 22/95: Readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 813d20b 07/95: Fix commands, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 802b04d 10/95: Fix cask, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter b9eb93f 13/95: Fix travis, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter b6b0fae 26/95: Readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter fc2e59f 35/95: More testing, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 8d70f15 16/95: Readme, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 98e0362 32/95: Recognize errors at reader level.,
Stefan Monnier <=
- [elpa] externals/bug-hunter 86a1664 31/95: Merge branch 'master' of github.com:Bruce-Connor/elisp-bug-hunter, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 16922e1 34/95: Fix test, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 2afa228 39/95: Letbind server-name to avoid conflicts, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter c076d3b 43/95: Improve interactive assertion prompt, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 2524718 55/95: Don't quote file name argument to `call-process`, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 0f9bd03 17/95: Copyright and deps, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 0fbf2a4 24/95: Run after-init-hooks, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 4da93d7 36/95: Provide full information on where the bug occurs., Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 80af9de 38/95: Ignore cask, Stefan Monnier, 2020/11/27
- [elpa] externals/bug-hunter 95d6857 44/95: DOC, Stefan Monnier, 2020/11/27