0
0
Fork 1
mirror of https://git.savannah.gnu.org/git/emacs/org-mode.git synced 2024-09-19 19:40:01 +00:00

org-element-cache: Add switch to verify cache before writing to disk

*
lisp/org-element.el (org-element--cache-self-verify-before-persisting):
New internal variable toggling full verification pass before writing
cache to disk.

* lisp/org-element.el (org-element--cache-persist-before-write):
Verify cache and throw error on failure when
`org-element--cache-self-verify-before-persisting' is non-nil.
This commit is contained in:
Ihor Radchenko 2023-09-22 11:42:52 +03:00
parent d73d85b05e
commit 7efd5bba0a
No known key found for this signature in database
GPG key ID: 6470762A7DA11D8B

View file

@ -5450,6 +5450,13 @@ of `org-element--cache-self-verify-frequency'.
When set to symbol `backtrace', record and display backtrace log if
any inconsistency is detected.")
(defvar org-element--cache-self-verify-before-persisting nil
"Perform consistency checks for the cache before writing to disk.
When non-nil, signal an error an show backtrace if cache contains
incorrect elements. `org-element--cache-self-verify' must be set to
symbol `backtrace' to have non-empty backtrace displayed.")
(defvar org-element--cache-self-verify-frequency 0.03
"Frequency of cache element verification.
@ -7360,9 +7367,10 @@ The element is: %S\n The real element is: %S\n Cache around :begin:\n%S\n%S\n%S"
(unless (org-element-type-p el2 'plain-text)
(org-element-put-property el2 :buffer nil)))
nil nil nil 'with-affiliated 'no-undefer)
(when (and (not (org-element-parent el)) (not (org-element-type-p el 'org-data)))
(org-element--cache-warn
"Got element without parent when writing cache to disk.\n%S" el)))
(let ((org-element--cache-self-verify-frequency 1.0))
(when (and org-element--cache-self-verify-before-persisting
(org-element--cache-verify-element el))
(error "Cache verification failed: aborting"))))
org-element--cache)
nil)
'forbid))