From 5483d0dd9087fa2c1542745b1565423ee8811056 Mon Sep 17 00:00:00 2001 From: JenChieh Date: Mon, 26 Jan 2026 03:07:22 +0800 Subject: [PATCH 1/2] fix: Report error only after command's execution --- lisp/_prepare.el | 36 ++++++++++++++++++--------- lisp/core/compile.el | 47 ++++++++++++++++-------------------- lisp/format/elfmt.el | 7 +----- lisp/format/elisp-autofmt.el | 4 +-- lisp/lint/checkdoc.el | 7 +----- lisp/lint/declare.el | 16 ++++++------ lisp/lint/elint.el | 8 ++---- lisp/lint/elisp-lint.el | 20 ++++++--------- lisp/lint/elsa.el | 28 +++++++++------------ lisp/lint/indent.el | 10 +++----- lisp/lint/keywords.el | 14 +++++------ lisp/lint/license.el | 5 ---- lisp/lint/org.el | 8 ++---- lisp/lint/package.el | 18 +++++--------- lisp/lint/regexps.el | 9 +++---- lisp/test/ert-runner.el | 14 +++++++---- lisp/test/melpazoid.el | 8 ++---- 17 files changed, 109 insertions(+), 150 deletions(-) diff --git a/lisp/_prepare.el b/lisp/_prepare.el index 903ba04f..41affd2c 100644 --- a/lisp/_prepare.el +++ b/lisp/_prepare.el @@ -185,14 +185,18 @@ will return `lint/checkdoc' with a dash between two subcommands." version))) (defun eask-command-p (commands) - "Return t if COMMANDS is the current command." + "Return t when the current command matches any entry in the COMMANDS list." (member (eask-command) (eask-listify commands))) (defun eask-special-p () "Return t if the command that can be run without Eask-file existence. These commands will first respect the current workspace. If the current -workspace has no valid Eask-file; it will load global workspace instead." +workspace has no valid Eask-file; it will load the Eask-file form the global +workspace instead. + +If there is no valid Eask-file presented; the execution continues without +printing the missing Eask-file message." (eask-command-p '("init" "init/source" "init/cask" "init/eldev" "init/keg" "create/package" "create/elpa" "create/el-project" "bump" "cat" "keywords" "repl" @@ -255,6 +259,14 @@ the `eask-start' execution.") ;; ;;; Util +(defmacro eask-add-hook (hooks &rest body) + "The eye candy for the function `add-hook'." + (declare (indent 1)) + `(cond ((listp ,hooks) + (dolist (hook ,hooks) + (add-hook hook (lambda (&optional arg0 arg1 arg2 &rest args) ,@body)))) + (t (add-hook ,hooks (lambda (&optional arg0 arg1 arg2 &rest args) ,@body))))) + (defmacro eask-defvc< (version &rest body) "Define scope if Emacs version is below VERSION. @@ -484,7 +496,7 @@ You can pass BUFFER-OR-NAME to replace current buffer." (line-end-position)))) ;; The variable `line' can contains format specifier, avoid it with `%s'! (cond ((string-match-p "[: ][Ee]rror: " line) - (eask-error "%s" line)) + (eask-ignore-errors (eask-error "%s" line))) ((string-match-p "[: ][Ww]arning: " line) (eask-warn "%s" line)) (t @@ -2032,6 +2044,7 @@ The argument ARGS is passed from the function `eask--error'." ;; Handle https://github.com/emacs-eask/cli/issues/11. (unless (string-prefix-p "Can't find library " (car args)) (setq eask--has-error-p t))) + ;; Flag the error normally. (t (setq eask--has-error-p t))) ; Just a record. @@ -2092,15 +2105,14 @@ Arguments FNC and ARGS are used for advice `:around'." (write-region (with-current-buffer ,buffer (buffer-string)) nil (expand-file-name ,file log-dir))))) -(add-hook 'kill-emacs-hook ; Write log files - (lambda (&rest _) - (when eask-log-file - (let ((log-dir (expand-file-name eask-log-path eask-file-root))) - (make-directory log-dir t) - (eask--log-write-buffer "*Messages*" "messages.log") - (eask--log-write-buffer "*Warnings*" "warnings.log") - (eask--log-write-buffer "*Backtrace*" "backtrace.log") - (eask--log-write-buffer "*Compile-Log*" "compile-log.log"))))) +(eask-add-hook '( kill-emacs-hook) + (when eask-log-file ; Write log files + (let ((log-dir (expand-file-name eask-log-path eask-file-root))) + (make-directory log-dir t) + (eask--log-write-buffer "*Messages*" "messages.log") + (eask--log-write-buffer "*Warnings*" "warnings.log") + (eask--log-write-buffer "*Backtrace*" "backtrace.log") + (eask--log-write-buffer "*Compile-Log*" "compile-log.log")))) ;; ;;; File diff --git a/lisp/core/compile.el b/lisp/core/compile.el index ec829e1d..bd61863c 100644 --- a/lisp/core/compile.el +++ b/lisp/core/compile.el @@ -19,20 +19,14 @@ (locate-dominating-file dir "_prepare.el")) nil t)) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Handle options -(add-hook 'eask-before-command-hook - (lambda () - (when (eask-strict-p) - (setq byte-compile-error-on-warn t)) - (when (eask-reach-verbosity-p 'debug) - (setq byte-compile-verbose t)))) +(eask-add-hook '( eask-before-command-hook) + (when (eask-strict-p) + (setq byte-compile-error-on-warn t)) + (when (eask-reach-verbosity-p 'debug) + (setq byte-compile-verbose t))) ;; ;;; Core @@ -98,21 +92,22 @@ The CMD is the command to start a new Emacs session." (defun eask-compile--byte-compile-file (filename) "Byte compile FILENAME." - ;; *Compile-Log* does not kill itself. Make sure it's clean before we do - ;; next byte-compile task. - (ignore-errors (kill-buffer byte-compile-log-buffer)) - (let* ((filename (expand-file-name filename)) - (result)) - (eask-with-progress - (unless byte-compile-verbose (format "Compiling %s... " filename)) - (eask-with-verbosity 'debug - (setq result (if (eask-clean-p) - (eask-compile--byte-compile-file-external filename) - (byte-compile-file filename)) - result (eq result t))) - (unless byte-compile-verbose (if result "done ✓" "skipped ✗"))) - (eask-compile--print-log) - result)) + (eask-ignore-errors + ;; *Compile-Log* does not kill itself. Make sure it's clean before we do + ;; next byte-compile task. + (ignore-errors (kill-buffer byte-compile-log-buffer)) + (let* ((filename (expand-file-name filename)) + (result)) + (eask-with-progress + (unless byte-compile-verbose (format "Compiling %s... " filename)) + (eask-with-verbosity 'debug + (setq result (if (eask-clean-p) + (eask-compile--byte-compile-file-external filename) + (byte-compile-file filename)) + result (eq result t))) + (unless byte-compile-verbose (if result "done ✓" "skipped ✗"))) + (eask-compile--print-log) + result))) (defun eask-compile--files (files) "Compile sequence of FILES." diff --git a/lisp/format/elfmt.el b/lisp/format/elfmt.el index 5f571d0e..b4d3310e 100644 --- a/lisp/format/elfmt.el +++ b/lisp/format/elfmt.el @@ -24,11 +24,6 @@ (declare-function elfmt-buffer "ext:elisp-autofmt.el") -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -40,7 +35,7 @@ (let* ((filename (expand-file-name filename)) (file (eask-root-del filename))) (with-current-buffer (find-file filename) - (elfmt-buffer) + (eask-ignore-errors (elfmt-buffer)) (save-buffer) (kill-buffer)))) diff --git a/lisp/format/elisp-autofmt.el b/lisp/format/elisp-autofmt.el index 7bff9083..c2d7af60 100644 --- a/lisp/format/elisp-autofmt.el +++ b/lisp/format/elisp-autofmt.el @@ -29,8 +29,6 @@ (eask-command-check "29.1") -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -42,7 +40,7 @@ (let* ((filename (expand-file-name filename)) (file (eask-root-del filename))) (with-current-buffer (find-file filename) - (elisp-autofmt-buffer) + (eask-ignore-errors (elisp-autofmt-buffer)) (save-buffer) (kill-buffer)))) diff --git a/lisp/lint/checkdoc.el b/lisp/lint/checkdoc.el index 350da67a..5c377b2e 100644 --- a/lisp/lint/checkdoc.el +++ b/lisp/lint/checkdoc.el @@ -27,11 +27,6 @@ (declare-function checkdoc-buffer-label "ext:checkdoc.el") -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -59,7 +54,7 @@ be assigned to variable `checkdoc-create-error-function'." (eask-lint-checkdoc--errors)) (eask-lint-first-newline) (eask-msg "`%s` with checkdoc (%s)" (ansi-green file) checkdoc-version) - (checkdoc-file filename) + (eask-ignore-errors (checkdoc-file filename)) (unless eask-lint-checkdoc--errors (eask-msg "No issues found")))) (eask-start diff --git a/lisp/lint/declare.el b/lisp/lint/declare.el index 807a2301..d2369603 100644 --- a/lisp/lint/declare.el +++ b/lisp/lint/declare.el @@ -24,11 +24,6 @@ (defvar check-declare-warning-buffer) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -40,10 +35,13 @@ (eask-lint-first-newline) (eask-msg "`%s` with check-declare" (ansi-green file)) (setq errors (eask--silent (check-declare-file filename))) - (if errors - (with-current-buffer check-declare-warning-buffer - (eask-report (string-remove-prefix " \n" (buffer-string)))) - (eask-msg "No issues found")))) + (eask-ignore-errors ; Continue checking. + (if errors + (with-current-buffer check-declare-warning-buffer + (eask-report + (string-remove-prefix " \n" + (buffer-string)))) + (eask-msg "No issues found"))))) (eask-start (require 'check-declare) diff --git a/lisp/lint/elint.el b/lisp/lint/elint.el index ede7f7a9..6ef8ec20 100644 --- a/lisp/lint/elint.el +++ b/lisp/lint/elint.el @@ -24,11 +24,6 @@ (declare-function elint-get-log-buffer "ext:elsa.el") -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -39,7 +34,8 @@ (noninteractive)) (eask-lint-first-newline) (eask-msg "`%s` with elint" (ansi-green file)) - (eask-with-verbosity 'debug (elint-file filename)) + (eask-with-verbosity 'debug + (eask-ignore-errors (elint-file filename))) (let ((log-buffer (elint-get-log-buffer))) (eask-print-log-buffer log-buffer) (kill-buffer log-buffer)))) diff --git a/lisp/lint/elisp-lint.el b/lisp/lint/elisp-lint.el index 58499de0..5369b4f9 100644 --- a/lisp/lint/elisp-lint.el +++ b/lisp/lint/elisp-lint.el @@ -24,11 +24,6 @@ (declare-function elisp-lint-file "ext:elsa.el") -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -42,13 +37,14 @@ success) (eask-msg "") (eask-msg "`%s` with elisp-lint (%s)" (ansi-green file) eask-lint-elisp-lint--version) - (eask-with-verbosity 'debug - (setq success (elisp-lint-file filename))) - ;; Report result! - (cond (success - (eask-msg "No issues found")) - ((eask-strict-p) - (eask-error "Linting failed"))))) + (eask-ignore-errors + (eask-with-verbosity 'debug + (setq success (elisp-lint-file filename))) + ;; Report result! + (cond (success + (eask-msg "No issues found")) + ((eask-strict-p) + (eask-error "Linting failed")))))) (eask-start ;; Preparation diff --git a/lisp/lint/elsa.el b/lisp/lint/elsa.el index 644e41fa..6de3cef6 100644 --- a/lisp/lint/elsa.el +++ b/lisp/lint/elsa.el @@ -30,11 +30,6 @@ (declare-function elsa-analyse-file "ext:elsa.el") (declare-function --each "ext:dash.el") -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -48,17 +43,18 @@ errors) (eask-msg "") (eask-msg "`%s` with elsa (%s)" (ansi-green file) eask-lint-elsa--version) - (eask-with-verbosity 'debug - (setq errors (oref (elsa-analyse-file filename elsa-global-state) errors))) - (if errors - (--each (reverse errors) - (let ((line (string-trim (concat file ":" (elsa-message-format it))))) - (cond ((string-match-p "[: ][Ee]rror:" line) - (eask-error "%s" line)) - ((string-match-p "[: ][Ww]arning:" line) - (eask-warn "%s" line)) - (t (eask-log "%s" line))))) - (eask-msg "No issues found")))) + (eask-ignore-errors + (eask-with-verbosity 'debug + (setq errors (oref (elsa-analyse-file filename elsa-global-state) errors))) + (if errors + (--each (reverse errors) + (let ((line (string-trim (concat file ":" (elsa-message-format it))))) + (cond ((string-match-p "[: ][Ee]rror:" line) + (eask-error "%s" line)) + ((string-match-p "[: ][Ww]arning:" line) + (eask-warn "%s" line)) + (t (eask-log "%s" line))))) + (eask-msg "No issues found"))))) (eask-start ;; Preparation diff --git a/lisp/lint/indent.el b/lisp/lint/indent.el index ea6c3e96..d9269e70 100644 --- a/lisp/lint/indent.el +++ b/lisp/lint/indent.el @@ -19,11 +19,6 @@ (locate-dominating-file dir "_prepare.el")) nil t)) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -61,8 +56,9 @@ (column (nth 1 info)) (current (eask-with-buffer (eask--goto-line line) (current-indentation)))) - (eask-report "%s:%s: Expected indentation is %s but found %s" - (buffer-name) line column current))) + (eask-ignore-errors + (eask-report "%s:%s: Expected indentation is %s but found %s" + (buffer-name) line column current)))) (eask-log "No mismatch indentation found")))) (eask-start diff --git a/lisp/lint/keywords.el b/lisp/lint/keywords.el index ac3f75de..7d24ad6b 100644 --- a/lisp/lint/keywords.el +++ b/lisp/lint/keywords.el @@ -14,11 +14,6 @@ (locate-dominating-file dir "_prepare.el")) nil t)) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -38,10 +33,12 @@ (file (eask-root-del eask-package-file))) (cond ((not eask-package-file) - (eask-report "Can't lint keywords without the package-file specified") + (eask-ignore-errors + (eask-report "Can't lint keywords without the package-file specified")) (eask-help "lint/keywords-file")) ((not keywords) - (eask-report "Keywords header seems to be missing in the `%s' file" file) + (eask-ignore-errors + (eask-report "Keywords header seems to be missing in the `%s' file" file)) (eask-help "lint/keywords-header")) (t (eask-lint-first-newline) @@ -50,7 +47,8 @@ (progn (eask-msg "") (eask-info "(No issues found.)")) - (eask-report "Missing a standard keyword, consider adding one to the Keywords header!") + (eask-ignore-errors + (eask-report "Missing a standard keyword, consider adding one to the Keywords header!")) (eask-help "lint/keywords")))))) ;;; lint/keywords.el ends here diff --git a/lisp/lint/license.el b/lisp/lint/license.el index 1f5f4bd5..84ae6dc0 100644 --- a/lisp/lint/license.el +++ b/lisp/lint/license.el @@ -19,11 +19,6 @@ (require 'whitespace nil t) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core diff --git a/lisp/lint/org.el b/lisp/lint/org.el index 583f5fc6..0c4bf4e2 100644 --- a/lisp/lint/org.el +++ b/lisp/lint/org.el @@ -19,11 +19,6 @@ (locate-dominating-file dir "_prepare.el")) nil t)) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -34,7 +29,7 @@ (line (elt data 0)) (text (elt data 2)) (msg (concat filename ":" line ": " text))) - (if (eask-strict-p) (error msg) (warn msg)))) + (eask-ignore-errors (eask-report "%s" msg)))) (defun eask-lint-org--file (file) "Run `org-lint' on FILE." @@ -60,6 +55,7 @@ (cond ;; Files found, do the action! (files + (eask-msg "") (mapcar #'eask-lint-org--file files) (eask-msg "") (eask-info "(Total of %s file%s linted)" (length files) diff --git a/lisp/lint/package.el b/lisp/lint/package.el index 676ddcdc..737ba0cf 100644 --- a/lisp/lint/package.el +++ b/lisp/lint/package.el @@ -24,21 +24,15 @@ (declare-function package-lint-current-buffer "ext:package-lint.el") -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Handle options -(add-hook 'eask-before-command-hook - (lambda () - (when (and (not (boundp 'package-lint-batch-fail-on-warnings)) - (not (eask-strict-p))) - ;; TODO: This doesn't work since this variable only controls - ;; `package-lint' exit code. - (setq package-lint-batch-fail-on-warnings nil)))) +(eask-add-hook '( eask-before-command-hook) + (when (and (not (boundp 'package-lint-batch-fail-on-warnings)) + (not (eask-strict-p))) + ;; TODO: This doesn't work since this variable only controls + ;; `package-lint' exit code. + (setq package-lint-batch-fail-on-warnings nil))) ;; ;;; Core diff --git a/lisp/lint/regexps.el b/lisp/lint/regexps.el index dfddef4f..6bf34ed2 100644 --- a/lisp/lint/regexps.el +++ b/lisp/lint/regexps.el @@ -29,8 +29,6 @@ (eask-command-check "27.1") -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -54,9 +52,10 @@ (`error #'eask-error) (`warning #'eask-warn) (_ #'eask-info)))) - (funcall report-func "%s:%s %s: %s" - file (line-number-at-pos error-pos) - (capitalize (eask-2str severity)) msg))) + (eask-ignore-errors + (funcall report-func "%s:%s %s: %s" + file (line-number-at-pos error-pos) + (capitalize (eask-2str severity)) msg)))) (unless errors (eask-msg "No issues found")) (kill-current-buffer)))) diff --git a/lisp/test/ert-runner.el b/lisp/test/ert-runner.el index 8defef5e..157edd2e 100644 --- a/lisp/test/ert-runner.el +++ b/lisp/test/ert-runner.el @@ -19,11 +19,15 @@ (locate-dominating-file dir "_prepare.el")) nil t)) -;; Handle options -(add-hook 'eask-before-command-hook - (lambda () - (when (eask-reach-verbosity-p 'debug) - (setq ert-runner-verbose t)))) +;; +;;; Handle options + +(eask-add-hook '( eask-before-command-hook) + (when (eask-reach-verbosity-p 'debug) + (setq ert-runner-verbose t))) + +;; +;;; Core (defun eask-test-ert-runner--run (fnc &rest args) "Run around function `ert-runner/run'. diff --git a/lisp/test/melpazoid.el b/lisp/test/melpazoid.el index 48dc16e6..6e5d89c4 100644 --- a/lisp/test/melpazoid.el +++ b/lisp/test/melpazoid.el @@ -14,11 +14,6 @@ (locate-dominating-file dir "_prepare.el")) nil t)) -;; -;;; Flags - -(advice-add #'eask-allow-error-p :override #'eask-always) - ;; ;;; Core @@ -42,7 +37,8 @@ (dolist (dir dirs) (let ((default-directory (expand-file-name dir))) (eask-info "[+] %s" default-directory) - (eask-import eask-test-melpazoid-el-url)))) + (eask-ignore-errors + (eask-import eask-test-melpazoid-el-url))))) ;; Default, print help! (t (eask-info "(No tests found.)") From aa219bc5789b809a1ea3f5d85bb9532f7d3f009d Mon Sep 17 00:00:00 2001 From: JenChieh Date: Mon, 26 Jan 2026 03:09:27 +0800 Subject: [PATCH 2/2] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 67326e36..e9226844 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how * fix(lisp): Let buttercup tests handle exit code themselves ([#385](../../pull/385)) * fix(lisp): Set up paths regardless of the working environment ([#386](../../pull/386)) * feat(cmds): Move `el2org` to docs subcommand ([#388](../../pull/388)) +* fix(lisp): Report error only inside the command's execution ([#389](../../pull/389)) ## 0.12.x > Released Dec 02, 2025