diff options
| author | Craig Jennings <c@cjennings.net> | 2026-05-05 05:16:39 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-05-05 05:16:39 -0500 |
| commit | f5d67d7a0a48cd68d7f443ca475c0c7bc59a8468 (patch) | |
| tree | fb5a08026058fdea861a248b1e7103bfea092166 | |
| parent | aa3d724c6bdd3a16391ad95040184c118386d329 (diff) | |
| download | org-drill-f5d67d7a0a48cd68d7f443ca475c0c7bc59a8468.tar.gz org-drill-f5d67d7a0a48cd68d7f443ca475c0c7bc59a8468.zip | |
fix: guard org-drill-again and org-drill-resume against nil last-session
Both functions bound session to org-drill-last-session and immediately
called setf / org-drill-entries-pending-p on it without checking for
nil. First-time invocation (or after Emacs restart with no active
session) threw an obscure eieio-oset / nil-slot type error instead
of a clear message.
Added (unless session (user-error ...)) at the top of each function.
A user running M-x org-drill-resume cold now sees a sensible message
telling them to run org-drill first.
| -rw-r--r-- | org-drill.el | 4 | ||||
| -rw-r--r-- | tests/test-org-drill-resume-nil-session.el | 39 |
2 files changed, 43 insertions, 0 deletions
diff --git a/org-drill.el b/org-drill.el index 97ba891..0de606c 100644 --- a/org-drill.el +++ b/org-drill.el @@ -3231,6 +3231,8 @@ unreviewed items. If there are no leftover items in memory, a full scan will be performed." (interactive) (let ((session org-drill-last-session)) + (unless session + (user-error "No previous drill session to continue — run `org-drill' first")) (setf (oref session cram-mode) nil) (cond ((cl-plusp (org-drill-pending-entry-count session)) @@ -3249,6 +3251,8 @@ scan will be performed." exiting them with the `edit' or `quit' options." (interactive) (let ((session org-drill-last-session)) + (unless session + (user-error "No suspended drill session to resume — run `org-drill' first")) (cond ((org-drill-entries-pending-p session) (org-drill nil nil t)) diff --git a/tests/test-org-drill-resume-nil-session.el b/tests/test-org-drill-resume-nil-session.el new file mode 100644 index 0000000..fd64faf --- /dev/null +++ b/tests/test-org-drill-resume-nil-session.el @@ -0,0 +1,39 @@ +;;; test-org-drill-resume-nil-session.el --- Regression for nil last-session -*- lexical-binding: t; -*- + +;;; Commentary: +;; `org-drill-again' and `org-drill-resume' bind a local `session' to +;; `org-drill-last-session' without checking for nil. On the first +;; ever invocation (or after Emacs restart with no active session), +;; org-drill-last-session is nil and both functions throw — `again' +;; on `(setf (oref session cram-mode) nil)' (eieio-oset on nil), +;; `resume' on `org-drill-entries-pending-p' walking nil's slots. +;; +;; Fixed by adding an early `(unless session (user-error ...))' to +;; both. A clear user-visible message replaces the obscure type +;; errors. + +;;; Code: + +(require 'ert) +(require 'cl-lib) +(require 'org) +(require 'org-drill) + +;;;; Regression — org-drill-again + +(ert-deftest test-org-drill-again-nil-last-session-raises-user-error () + "Calling org-drill-again with no prior session triggers a user-error, +not an obscure eieio type error." + (let ((org-drill-last-session nil)) + (should-error (org-drill-again) :type 'user-error))) + +;;;; Regression — org-drill-resume + +(ert-deftest test-org-drill-resume-nil-last-session-raises-user-error () + "Calling org-drill-resume with no prior session triggers a user-error." + (let ((org-drill-last-session nil)) + (should-error (org-drill-resume) :type 'user-error))) + +(provide 'test-org-drill-resume-nil-session) + +;;; test-org-drill-resume-nil-session.el ends here |
