Skip to content

Commit 931a06b

Browse files
authored
fix: Report error only after command's execution (#389)
* fix: Report error only after command's execution * changelog
1 parent e986a36 commit 931a06b

18 files changed

Lines changed: 110 additions & 150 deletions

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how
1414
* fix(lisp): Let buttercup tests handle exit code themselves ([#385](../../pull/385))
1515
* fix(lisp): Set up paths regardless of the working environment ([#386](../../pull/386))
1616
* feat(cmds): Move `el2org` to docs subcommand ([#388](../../pull/388))
17+
* fix(lisp): Report error only inside the command's execution ([#389](../../pull/389))
1718

1819
## 0.12.x
1920
> Released Dec 02, 2025

lisp/_prepare.el

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,18 @@ will return `lint/checkdoc' with a dash between two subcommands."
185185
version)))
186186

187187
(defun eask-command-p (commands)
188-
"Return t if COMMANDS is the current command."
188+
"Return t when the current command matches any entry in the COMMANDS list."
189189
(member (eask-command) (eask-listify commands)))
190190

191191
(defun eask-special-p ()
192192
"Return t if the command that can be run without Eask-file existence.
193193
194194
These commands will first respect the current workspace. If the current
195-
workspace has no valid Eask-file; it will load global workspace instead."
195+
workspace has no valid Eask-file; it will load the Eask-file form the global
196+
workspace instead.
197+
198+
If there is no valid Eask-file presented; the execution continues without
199+
printing the missing Eask-file message."
196200
(eask-command-p '("init" "init/source" "init/cask" "init/eldev" "init/keg"
197201
"create/package" "create/elpa" "create/el-project"
198202
"bump" "cat" "keywords" "repl"
@@ -255,6 +259,14 @@ the `eask-start' execution.")
255259
;;
256260
;;; Util
257261

262+
(defmacro eask-add-hook (hooks &rest body)
263+
"The eye candy for the function `add-hook'."
264+
(declare (indent 1))
265+
`(cond ((listp ,hooks)
266+
(dolist (hook ,hooks)
267+
(add-hook hook (lambda (&optional arg0 arg1 arg2 &rest args) ,@body))))
268+
(t (add-hook ,hooks (lambda (&optional arg0 arg1 arg2 &rest args) ,@body)))))
269+
258270
(defmacro eask-defvc< (version &rest body)
259271
"Define scope if Emacs version is below VERSION.
260272
@@ -484,7 +496,7 @@ You can pass BUFFER-OR-NAME to replace current buffer."
484496
(line-end-position))))
485497
;; The variable `line' can contains format specifier, avoid it with `%s'!
486498
(cond ((string-match-p "[: ][Ee]rror: " line)
487-
(eask-error "%s" line))
499+
(eask-ignore-errors (eask-error "%s" line)))
488500
((string-match-p "[: ][Ww]arning: " line)
489501
(eask-warn "%s" line))
490502
(t
@@ -2032,6 +2044,7 @@ The argument ARGS is passed from the function `eask--error'."
20322044
;; Handle https://github.com/emacs-eask/cli/issues/11.
20332045
(unless (string-prefix-p "Can't find library " (car args))
20342046
(setq eask--has-error-p t)))
2047+
;; Flag the error normally.
20352048
(t
20362049
(setq eask--has-error-p t))) ; Just a record.
20372050

@@ -2092,15 +2105,14 @@ Arguments FNC and ARGS are used for advice `:around'."
20922105
(write-region (with-current-buffer ,buffer (buffer-string)) nil
20932106
(expand-file-name ,file log-dir)))))
20942107

2095-
(add-hook 'kill-emacs-hook ; Write log files
2096-
(lambda (&rest _)
2097-
(when eask-log-file
2098-
(let ((log-dir (expand-file-name eask-log-path eask-file-root)))
2099-
(make-directory log-dir t)
2100-
(eask--log-write-buffer "*Messages*" "messages.log")
2101-
(eask--log-write-buffer "*Warnings*" "warnings.log")
2102-
(eask--log-write-buffer "*Backtrace*" "backtrace.log")
2103-
(eask--log-write-buffer "*Compile-Log*" "compile-log.log")))))
2108+
(eask-add-hook '( kill-emacs-hook)
2109+
(when eask-log-file ; Write log files
2110+
(let ((log-dir (expand-file-name eask-log-path eask-file-root)))
2111+
(make-directory log-dir t)
2112+
(eask--log-write-buffer "*Messages*" "messages.log")
2113+
(eask--log-write-buffer "*Warnings*" "warnings.log")
2114+
(eask--log-write-buffer "*Backtrace*" "backtrace.log")
2115+
(eask--log-write-buffer "*Compile-Log*" "compile-log.log"))))
21042116

21052117
;;
21062118
;;; File

lisp/core/compile.el

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,14 @@
1919
(locate-dominating-file dir "_prepare.el"))
2020
nil t))
2121

22-
;;
23-
;;; Flags
24-
25-
(advice-add #'eask-allow-error-p :override #'eask-always)
26-
2722
;;
2823
;;; Handle options
2924

30-
(add-hook 'eask-before-command-hook
31-
(lambda ()
32-
(when (eask-strict-p)
33-
(setq byte-compile-error-on-warn t))
34-
(when (eask-reach-verbosity-p 'debug)
35-
(setq byte-compile-verbose t))))
25+
(eask-add-hook '( eask-before-command-hook)
26+
(when (eask-strict-p)
27+
(setq byte-compile-error-on-warn t))
28+
(when (eask-reach-verbosity-p 'debug)
29+
(setq byte-compile-verbose t)))
3630

3731
;;
3832
;;; Core
@@ -98,21 +92,22 @@ The CMD is the command to start a new Emacs session."
9892

9993
(defun eask-compile--byte-compile-file (filename)
10094
"Byte compile FILENAME."
101-
;; *Compile-Log* does not kill itself. Make sure it's clean before we do
102-
;; next byte-compile task.
103-
(ignore-errors (kill-buffer byte-compile-log-buffer))
104-
(let* ((filename (expand-file-name filename))
105-
(result))
106-
(eask-with-progress
107-
(unless byte-compile-verbose (format "Compiling %s... " filename))
108-
(eask-with-verbosity 'debug
109-
(setq result (if (eask-clean-p)
110-
(eask-compile--byte-compile-file-external filename)
111-
(byte-compile-file filename))
112-
result (eq result t)))
113-
(unless byte-compile-verbose (if result "done ✓" "skipped ✗")))
114-
(eask-compile--print-log)
115-
result))
95+
(eask-ignore-errors
96+
;; *Compile-Log* does not kill itself. Make sure it's clean before we do
97+
;; next byte-compile task.
98+
(ignore-errors (kill-buffer byte-compile-log-buffer))
99+
(let* ((filename (expand-file-name filename))
100+
(result))
101+
(eask-with-progress
102+
(unless byte-compile-verbose (format "Compiling %s... " filename))
103+
(eask-with-verbosity 'debug
104+
(setq result (if (eask-clean-p)
105+
(eask-compile--byte-compile-file-external filename)
106+
(byte-compile-file filename))
107+
result (eq result t)))
108+
(unless byte-compile-verbose (if result "done ✓" "skipped ✗")))
109+
(eask-compile--print-log)
110+
result)))
116111

117112
(defun eask-compile--files (files)
118113
"Compile sequence of FILES."

lisp/format/elfmt.el

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
(declare-function elfmt-buffer "ext:elisp-autofmt.el")
2626

27-
;;
28-
;;; Flags
29-
30-
(advice-add #'eask-allow-error-p :override #'eask-always)
31-
3227
;;
3328
;;; Core
3429

@@ -40,7 +35,7 @@
4035
(let* ((filename (expand-file-name filename))
4136
(file (eask-root-del filename)))
4237
(with-current-buffer (find-file filename)
43-
(elfmt-buffer)
38+
(eask-ignore-errors (elfmt-buffer))
4439
(save-buffer)
4540
(kill-buffer))))
4641

lisp/format/elisp-autofmt.el

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
(eask-command-check "29.1")
3131

32-
(advice-add #'eask-allow-error-p :override #'eask-always)
33-
3432
;;
3533
;;; Core
3634

@@ -42,7 +40,7 @@
4240
(let* ((filename (expand-file-name filename))
4341
(file (eask-root-del filename)))
4442
(with-current-buffer (find-file filename)
45-
(elisp-autofmt-buffer)
43+
(eask-ignore-errors (elisp-autofmt-buffer))
4644
(save-buffer)
4745
(kill-buffer))))
4846

lisp/lint/checkdoc.el

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,6 @@
2727

2828
(declare-function checkdoc-buffer-label "ext:checkdoc.el")
2929

30-
;;
31-
;;; Flags
32-
33-
(advice-add #'eask-allow-error-p :override #'eask-always)
34-
3530
;;
3631
;;; Core
3732

@@ -59,7 +54,7 @@ be assigned to variable `checkdoc-create-error-function'."
5954
(eask-lint-checkdoc--errors))
6055
(eask-lint-first-newline)
6156
(eask-msg "`%s` with checkdoc (%s)" (ansi-green file) checkdoc-version)
62-
(checkdoc-file filename)
57+
(eask-ignore-errors (checkdoc-file filename))
6358
(unless eask-lint-checkdoc--errors (eask-msg "No issues found"))))
6459

6560
(eask-start

lisp/lint/declare.el

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
(defvar check-declare-warning-buffer)
2626

27-
;;
28-
;;; Flags
29-
30-
(advice-add #'eask-allow-error-p :override #'eask-always)
31-
3227
;;
3328
;;; Core
3429

@@ -40,10 +35,13 @@
4035
(eask-lint-first-newline)
4136
(eask-msg "`%s` with check-declare" (ansi-green file))
4237
(setq errors (eask--silent (check-declare-file filename)))
43-
(if errors
44-
(with-current-buffer check-declare-warning-buffer
45-
(eask-report (string-remove-prefix " \n" (buffer-string))))
46-
(eask-msg "No issues found"))))
38+
(eask-ignore-errors ; Continue checking.
39+
(if errors
40+
(with-current-buffer check-declare-warning-buffer
41+
(eask-report
42+
(string-remove-prefix " \n"
43+
(buffer-string))))
44+
(eask-msg "No issues found")))))
4745

4846
(eask-start
4947
(require 'check-declare)

lisp/lint/elint.el

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
(declare-function elint-get-log-buffer "ext:elsa.el")
2626

27-
;;
28-
;;; Flags
29-
30-
(advice-add #'eask-allow-error-p :override #'eask-always)
31-
3227
;;
3328
;;; Core
3429

@@ -39,7 +34,8 @@
3934
(noninteractive))
4035
(eask-lint-first-newline)
4136
(eask-msg "`%s` with elint" (ansi-green file))
42-
(eask-with-verbosity 'debug (elint-file filename))
37+
(eask-with-verbosity 'debug
38+
(eask-ignore-errors (elint-file filename)))
4339
(let ((log-buffer (elint-get-log-buffer)))
4440
(eask-print-log-buffer log-buffer)
4541
(kill-buffer log-buffer))))

lisp/lint/elisp-lint.el

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@
2424

2525
(declare-function elisp-lint-file "ext:elsa.el")
2626

27-
;;
28-
;;; Flags
29-
30-
(advice-add #'eask-allow-error-p :override #'eask-always)
31-
3227
;;
3328
;;; Core
3429

@@ -42,13 +37,14 @@
4237
success)
4338
(eask-msg "")
4439
(eask-msg "`%s` with elisp-lint (%s)" (ansi-green file) eask-lint-elisp-lint--version)
45-
(eask-with-verbosity 'debug
46-
(setq success (elisp-lint-file filename)))
47-
;; Report result!
48-
(cond (success
49-
(eask-msg "No issues found"))
50-
((eask-strict-p)
51-
(eask-error "Linting failed")))))
40+
(eask-ignore-errors
41+
(eask-with-verbosity 'debug
42+
(setq success (elisp-lint-file filename)))
43+
;; Report result!
44+
(cond (success
45+
(eask-msg "No issues found"))
46+
((eask-strict-p)
47+
(eask-error "Linting failed"))))))
5248

5349
(eask-start
5450
;; Preparation

lisp/lint/elsa.el

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@
3030
(declare-function elsa-analyse-file "ext:elsa.el")
3131
(declare-function --each "ext:dash.el")
3232

33-
;;
34-
;;; Flags
35-
36-
(advice-add #'eask-allow-error-p :override #'eask-always)
37-
3833
;;
3934
;;; Core
4035

@@ -48,17 +43,18 @@
4843
errors)
4944
(eask-msg "")
5045
(eask-msg "`%s` with elsa (%s)" (ansi-green file) eask-lint-elsa--version)
51-
(eask-with-verbosity 'debug
52-
(setq errors (oref (elsa-analyse-file filename elsa-global-state) errors)))
53-
(if errors
54-
(--each (reverse errors)
55-
(let ((line (string-trim (concat file ":" (elsa-message-format it)))))
56-
(cond ((string-match-p "[: ][Ee]rror:" line)
57-
(eask-error "%s" line))
58-
((string-match-p "[: ][Ww]arning:" line)
59-
(eask-warn "%s" line))
60-
(t (eask-log "%s" line)))))
61-
(eask-msg "No issues found"))))
46+
(eask-ignore-errors
47+
(eask-with-verbosity 'debug
48+
(setq errors (oref (elsa-analyse-file filename elsa-global-state) errors)))
49+
(if errors
50+
(--each (reverse errors)
51+
(let ((line (string-trim (concat file ":" (elsa-message-format it)))))
52+
(cond ((string-match-p "[: ][Ee]rror:" line)
53+
(eask-error "%s" line))
54+
((string-match-p "[: ][Ww]arning:" line)
55+
(eask-warn "%s" line))
56+
(t (eask-log "%s" line)))))
57+
(eask-msg "No issues found")))))
6258

6359
(eask-start
6460
;; Preparation

0 commit comments

Comments
 (0)