[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dict-tree 22d569e 153/154: Improve error reporting when
From: |
Stefan Monnier |
Subject: |
[elpa] externals/dict-tree 22d569e 153/154: Improve error reporting when reading dictionary data from dumped file. |
Date: |
Mon, 14 Dec 2020 12:22:05 -0500 (EST) |
branch: externals/dict-tree
commit 22d569ef09db07f0ff303838158cbc093b6d78a7
Author: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Commit: Toby S. Cubitt <toby-predictive@dr-qubit.org>
Improve error reporting when reading dictionary data from dumped file.
---
dict-tree.el | 62 ++++++++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 46 insertions(+), 16 deletions(-)
diff --git a/dict-tree.el b/dict-tree.el
index e181665..e318daa 100644
--- a/dict-tree.el
+++ b/dict-tree.el
@@ -3878,35 +3878,65 @@ are created when using a trie that is not
self-balancing, see
(defun dictree--populate (dict &optional line file
insert-function key-loadfun data-loadfun
plist-loadfun)
;; Read entry from current line of current buffer, and insert it in DICT.
- (let (entry)
- (when (setq entry
- (condition-case nil
- (dictree--read-line key-loadfun data-loadfun plist-loadfun)
- (error (error "Error reading line %d of %s" line file))))
- (dictree-insert dict (car entry) (nth 1 entry) insert-function)
- (setf (dictree--cell-plist
- (dictree--lookup dict (car entry) nil))
- (nth 2 entry)))))
+ (destructuring-bind (key data plist)
+ (dictree--read-line line file key-loadfun data-loadfun plist-loadfun)
+ ;; insert entry in DICT
+ (dictree-insert dict key data insert-function)
+ (setf (dictree--cell-plist (dictree--lookup dict key nil)) plist)))
(defun dictree--read-line
- (&optional key-loadfun data-loadfun plist-loadfun)
+ (&optional line file key-loadfun data-loadfun plist-loadfun)
;; Return a list containing the key, data (if any, otherwise nil) and
;; property list (ditto) at the current line of the current buffer.
(save-excursion
(let (key data plist)
;; read key
(beginning-of-line)
- (when (setq key (read (current-buffer)))
- (when key-loadfun (setq key (funcall key-loadfun key)))
+ (when (setq key (condition-case nil
+ (read (current-buffer))
+ (error (error "Error reading key from line %d of %s"
+ line file))))
+ (when key-loadfun
+ (setq key (condition-case nil
+ (funcall key-loadfun key)
+ (error (error "Error calling KEY-LOADFUN on key read from
line %d of %s"
+ line file)))))
;; if there's anything after the key, use it as data
(unless (eq (line-end-position) (point))
- (setq data (read (current-buffer))))
- (when data-loadfun (setq data (funcall data-loadfun data)))
+ (setq data (condition-case nil
+ (read (current-buffer))
+ (error (error "Error reading data from line %d of %s"
+ line file)))))
+ (when data-loadfun
+ (setq data
+ (condition-case nil
+ (funcall data-loadfun data)
+ (error (error "Error calling DATA-LOADFUN on data read from
line %d of %s"
+ line file)))))
;; if there's anything after the data, use it as the property list
(unless (eq (line-end-position) (point))
- (setq plist (read (current-buffer))))
- (when plist-loadfun (funcall plist-loadfun plist))
+ (setq plist
+ (condition-case nil
+ (read (current-buffer))
+ (error (error "Error reading plist from line %d of %s"
+ line file)))))
+ (when plist-loadfun
+ (setq plist
+ (condition-case nil
+ (funcall plist-loadfun plist)
+ (error (error "Error calling PLIST-LOADFUN on plist read from
line %d of %s"
+ line file)))))
+
+ ;; sanity check what we read from file
+ (if (symbolp key)
+ (setq key (symbol-name key))
+ (unless (or (vectorp key) (stringp key) (listp key))
+ (error "Invalid key at line %d of %s - must be string, vector, list
or symbol"
+ line file)))
+ (unless (and (listp plist) (cl-evenp (length plist)))
+ (error "Invalid plist at line %d of %s" line file))
+
;; return what we've read
(list key data plist)))))
- [elpa] externals/dict-tree 95d6a5a 127/154: Mention iterator generators in Commentary., (continued)
- [elpa] externals/dict-tree 95d6a5a 127/154: Mention iterator generators in Commentary., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree d84725e 124/154: Bump version numbers since we've added iterator generators., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree f47d49c 137/154: Bug fixes to meta-dict fuzzy-matching/completing., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 65b94b4 131/154: Bump version numbers., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree c737d3a 134/154: Make use of new trie-fuzzy-complete facilities., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree eec26c3 132/154: Fix trie--construct-Lewenstein-rankfun to new versions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 5e2ffac 136/154: Test for lexical binding must be within same file to work reliably., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 22d0e13 140/154: Sort completions by fuzzy dist before ngram length., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 67afade 151/154: Document PFXFILTER argument to query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4299171 150/154: Work around Emacs bug preventing dict-tree caching., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 22d569e 153/154: Improve error reporting when reading dictionary data from dumped file.,
Stefan Monnier <=
- [elpa] externals/dict-tree f0af36e 148/154: Fix byte-compilation of functions embedded in dict-trees., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree dd695da 147/154: Display more informative message during writing dict to file., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 45270bc 144/154: Cache all queries, not just those with named function arguments., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 1db3424 128/154: Fix quoting of ' in one docstring., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 77f7b3a 133/154: Minor code refactoring., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 63b59a2 135/154: Implement fuzzy-completion with fixed initial prefix segment., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 4381f72 114/154: Generate caches as needed instead of at dict-tree creation., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree ad600f8 116/154: Fix data wrapping handling in fuzzy query functions., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 8d134c2 110/154: Fix bug in dictree-create with empty NAME argument., Stefan Monnier, 2020/12/14
- [elpa] externals/dict-tree 3c4b666 142/154: Refactored and rationalised dict saving/loading code., Stefan Monnier, 2020/12/14