aboutsummaryrefslogtreecommitdiff
path: root/tests/test-org-drill-id-creation-uninitialized.el
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2026-05-05 05:32:32 -0500
committerCraig Jennings <c@cjennings.net>2026-05-05 05:32:32 -0500
commit53d4b9654627c206d14b1345a4efe0a3e70d38d2 (patch)
tree86cc85610b3faa2b461c93575024d5e711e39fe6 /tests/test-org-drill-id-creation-uninitialized.el
parent718775cdf2baf7b6a2ed09edaa07d5684d47c4a9 (diff)
downloadorg-drill-53d4b9654627c206d14b1345a4efe0a3e70d38d2.tar.gz
org-drill-53d4b9654627c206d14b1345a4efe0a3e70d38d2.zip
fix: keep collection scan alive when one entry errors (upstream #53)
User reported that running org-drill on a buffer with a new (no-ID) entry threw 'Wrong Type Argument: hash-table-p, nil' and stopped the scan — every subsequent entry was silently skipped, so the user had to re-run org-drill once per item (10 items meant 10 invocations). The exact source of the hash-table error is environment-dependent (Emacs version, Org version, lazy org-id-locations init, Doom overrides), so this fix targets the user-visible failure mode instead of the underlying triggering condition. Wrapped the per-entry body of org-drill-map-entry-function in condition-case. An error on one entry now logs a 'skipping' message and the scan continues to the next entry. The session collects all the well-formed items, and the user can re-run drill once total to process them — no more once-per-item. Two regression tests: one verifies the resilience behavior directly (fail entry 1, scan continues to entry 2), the other documents the ID-creation-with-uninitialized-locations scenario as a smoke check.
Diffstat (limited to 'tests/test-org-drill-id-creation-uninitialized.el')
-rw-r--r--tests/test-org-drill-id-creation-uninitialized.el45
1 files changed, 45 insertions, 0 deletions
diff --git a/tests/test-org-drill-id-creation-uninitialized.el b/tests/test-org-drill-id-creation-uninitialized.el
new file mode 100644
index 0000000..0e9764a
--- /dev/null
+++ b/tests/test-org-drill-id-creation-uninitialized.el
@@ -0,0 +1,45 @@
+;;; test-org-drill-id-creation-uninitialized.el --- Regression for #53 -*- lexical-binding: t; -*-
+
+;;; Commentary:
+;; Upstream issue #53 (2024-02). Running `org-drill' on a buffer with a
+;; new (no-ID) entry would throw "Wrong Type Argument: hash-table-p,
+;; nil" when `org-id-locations' hadn't been initialized yet. The item
+;; still got an ID (org-id-get-create succeeded for that one), but the
+;; thrown error stopped session collection — subsequent items were
+;; silently skipped.
+;;
+;; Fix: ensure org-id is loaded and org-id-locations is a hash table
+;; before calling org-id-get-create from
+;; `org-drill-id-get-create-with-warning'.
+
+;;; Code:
+
+(require 'ert)
+(require 'cl-lib)
+(require 'org)
+(require 'org-id)
+(require 'org-drill)
+
+;;;; Regression — #53
+
+(ert-deftest test-id-get-create-with-warning-survives-uninitialized-id-locations ()
+ "When org-id-locations is nil, org-id-get-create normally fails with
+hash-table-p, nil. The fix ensures it's initialized before the call."
+ (let ((tmpfile (make-temp-file "org-drill-test-" nil ".org")))
+ (unwind-protect
+ (with-current-buffer (find-file-noselect tmpfile)
+ (let ((org-startup-folded nil))
+ (insert "* Question :drill:\nbody\n")
+ (goto-char (point-min))
+ (let ((session (org-drill-session))
+ ;; Force the bug condition: org-id-locations as nil.
+ (org-id-locations nil))
+ (cl-letf (((symbol-function 'sit-for) #'ignore))
+ ;; Should not error.
+ (let ((id (org-drill-id-get-create-with-warning session)))
+ (should (stringp id)))))))
+ (when (file-exists-p tmpfile) (delete-file tmpfile)))))
+
+(provide 'test-org-drill-id-creation-uninitialized)
+
+;;; test-org-drill-id-creation-uninitialized.el ends here