mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-02-17 23:53:15 +01:00
emacs: Fix bug in resynchronizing after a JSON parse error
Previously, if the input stream consisted only of an error message, notmuch-json-begin-compound would signal a (wrong-type-argument number-or-marker-p nil) error when reaching the end of the error message. This happened because notmuch-json-scan-to-value would think that it reached a value and put the parser into the 'value state. Even after notmuch-json-begin-compound signaled the syntax error, the parser would remain in this state and when the resynchronization logic reached the end of the buffer, the parser would fail because the 'value state indicates that characters are available. This fixes this problem by restoring the parser's previous state if it encounters a syntax error.
This commit is contained in:
parent
327f30a8f3
commit
d0ebd6cb53
1 changed files with 13 additions and 9 deletions
|
@ -465,15 +465,19 @@ Entering JSON objects is currently unimplemented."
|
||||||
(with-current-buffer (notmuch-json-buffer jp)
|
(with-current-buffer (notmuch-json-buffer jp)
|
||||||
;; Disallow terminators
|
;; Disallow terminators
|
||||||
(setf (notmuch-json-allow-term jp) nil)
|
(setf (notmuch-json-allow-term jp) nil)
|
||||||
(or (notmuch-json-scan-to-value jp)
|
;; Save "next" so we can restore it if there's a syntax error
|
||||||
(if (/= (char-after) ?\[)
|
(let ((saved-next (notmuch-json-next jp)))
|
||||||
(signal 'json-readtable-error (list "expected '['"))
|
(or (notmuch-json-scan-to-value jp)
|
||||||
(forward-char)
|
(if (/= (char-after) ?\[)
|
||||||
(push ?\] (notmuch-json-term-stack jp))
|
(progn
|
||||||
;; Expect a value or terminator next
|
(setf (notmuch-json-next jp) saved-next)
|
||||||
(setf (notmuch-json-next jp) 'expect-value
|
(signal 'json-readtable-error (list "expected '['")))
|
||||||
(notmuch-json-allow-term jp) t)
|
(forward-char)
|
||||||
t))))
|
(push ?\] (notmuch-json-term-stack jp))
|
||||||
|
;; Expect a value or terminator next
|
||||||
|
(setf (notmuch-json-next jp) 'expect-value
|
||||||
|
(notmuch-json-allow-term jp) t)
|
||||||
|
t)))))
|
||||||
|
|
||||||
(defun notmuch-json-read (jp)
|
(defun notmuch-json-read (jp)
|
||||||
"Parse the value at point in JP's buffer.
|
"Parse the value at point in JP's buffer.
|
||||||
|
|
Loading…
Add table
Reference in a new issue