unofficial mirror of notmuch@notmuchmail.org
 help / color / mirror / code / Atom feed
* [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error
@ 2012-12-14 15:07 Austin Clements
  2012-12-15 15:54 ` Tomi Ollila
  2012-12-15 18:35 ` David Bremner
  0 siblings, 2 replies; 3+ messages in thread
From: Austin Clements @ 2012-12-14 15:07 UTC (permalink / raw)
  To: notmuch

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 patch was already okayed by Mark Walters [0] in the context of a
larger series.  Since it's independent of that larger series, I'm
re-sending it separately.

[0] id:87hanxgczt.fsf@qmul.ac.uk

 emacs/notmuch-lib.el |   22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
index 9c4ee71..fb6d3e7 100644
--- a/emacs/notmuch-lib.el
+++ b/emacs/notmuch-lib.el
@@ -465,15 +465,19 @@ Entering JSON objects is currently unimplemented."
   (with-current-buffer (notmuch-json-buffer jp)
     ;; Disallow terminators
     (setf (notmuch-json-allow-term jp) nil)
-    (or (notmuch-json-scan-to-value jp)
-	(if (/= (char-after) ?\[)
-	    (signal 'json-readtable-error (list "expected '['"))
-	  (forward-char)
-	  (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))))
+    ;; Save "next" so we can restore it if there's a syntax error
+    (let ((saved-next (notmuch-json-next jp)))
+      (or (notmuch-json-scan-to-value jp)
+	  (if (/= (char-after) ?\[)
+	      (progn
+		(setf (notmuch-json-next jp) saved-next)
+		(signal 'json-readtable-error (list "expected '['")))
+	    (forward-char)
+	    (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)
   "Parse the value at point in JP's buffer.
-- 
1.7.10.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error
  2012-12-14 15:07 [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error Austin Clements
@ 2012-12-15 15:54 ` Tomi Ollila
  2012-12-15 18:35 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: Tomi Ollila @ 2012-12-15 15:54 UTC (permalink / raw)
  To: Austin Clements, notmuch

On Fri, Dec 14 2012, Austin Clements <amdragon@MIT.EDU> wrote:

> 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.
> ---

I couldn't understand this (setf... even reading the docstring
(and no time to experiment)
anyway the code change is pretty trivial and i cannot see what
it could break. I believe the code works as expected, so

+1

Tomi

>
> This patch was already okayed by Mark Walters [0] in the context of a
> larger series.  Since it's independent of that larger series, I'm
> re-sending it separately.
>
> [0] id:87hanxgczt.fsf@qmul.ac.uk
>
>  emacs/notmuch-lib.el |   22 +++++++++++++---------
>  1 file changed, 13 insertions(+), 9 deletions(-)
>
> diff --git a/emacs/notmuch-lib.el b/emacs/notmuch-lib.el
> index 9c4ee71..fb6d3e7 100644
> --- a/emacs/notmuch-lib.el
> +++ b/emacs/notmuch-lib.el
> @@ -465,15 +465,19 @@ Entering JSON objects is currently unimplemented."
>    (with-current-buffer (notmuch-json-buffer jp)
>      ;; Disallow terminators
>      (setf (notmuch-json-allow-term jp) nil)
> -    (or (notmuch-json-scan-to-value jp)
> -	(if (/= (char-after) ?\[)
> -	    (signal 'json-readtable-error (list "expected '['"))
> -	  (forward-char)
> -	  (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))))
> +    ;; Save "next" so we can restore it if there's a syntax error
> +    (let ((saved-next (notmuch-json-next jp)))
> +      (or (notmuch-json-scan-to-value jp)
> +	  (if (/= (char-after) ?\[)
> +	      (progn
> +		(setf (notmuch-json-next jp) saved-next)
> +		(signal 'json-readtable-error (list "expected '['")))
> +	    (forward-char)
> +	    (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)
>    "Parse the value at point in JP's buffer.
> -- 
> 1.7.10.4
>
> _______________________________________________
> notmuch mailing list
> notmuch@notmuchmail.org
> http://notmuchmail.org/mailman/listinfo/notmuch

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error
  2012-12-14 15:07 [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error Austin Clements
  2012-12-15 15:54 ` Tomi Ollila
@ 2012-12-15 18:35 ` David Bremner
  1 sibling, 0 replies; 3+ messages in thread
From: David Bremner @ 2012-12-15 18:35 UTC (permalink / raw)
  To: Austin Clements, notmuch

Austin Clements <amdragon@MIT.EDU> writes:

> 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.

pushed.

d

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2012-12-15 18:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-12-14 15:07 [PATCH] emacs: Fix bug in resynchronizing after a JSON parse error Austin Clements
2012-12-15 15:54 ` Tomi Ollila
2012-12-15 18:35 ` David Bremner

Code repositories for project(s) associated with this public inbox

	https://yhetil.org/notmuch.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).