[PATCH] emacs: make sure tagging on an empty query is harmless
David Edmondson
dme at dme.org
Wed May 21 03:47:23 PDT 2014
On Wed, May 21 2014, Mark Walters wrote:
> Currently notmuch-tag throws a "wrong-type-argument stringp nil" if
> passed a nil query-string. Catch this and provide a more useful error
> message. This fixes a case in notmuch-tree (if you try to tag when at
> the end of the buffer).
>
> Secondly, as pointed out by David (dme)
> `notmuch-search-find-stable-query-region' can return the query string
> () if there are no messages in the region. This gets passed to notmuch
> tag, and due to interactions in the optimize_query code in
> notmuch-tag.c becomes, in the case tag-change is -inbox, "( () ) and
> (tag:inbox)". This query matches some strange collection of messages
> which then get archived. This should probably be fixed, but in any
> case make `notmuch-search-find-stable-query-region' return a nil
> query-string in this case.
>
> This avoids data-loss (random tag removal) in this case.
> ---
>
> This is my attempt to solve the same problem as the parent. I prefer
> not throwing an error in n.s.f.s.q.r as it is difficult for the caller
> to catch cleanly. Throwing it in notmuch-tag is fine as the caller can
> trivially check for query-string being nil before calling notmuch-tag
> if it wants to deal with it gracefully.
>
> If people do prefer an error in n.s.f.s.q.r as in the parent patch
> then I think we should update the error message. The first hunk of
> this should also be applied to catch nil queries to notmuch-tag gracefully.
I'm fine with this approach.
> Although this has been present for a while I think it is a dataloss
> issue so a fix should go in for 0.18.1
As someone who has had to reconstruct a couple of times after being
bitten by this, I would agree.
> Best wishes
>
> Mark
>
>
>
>
> emacs/notmuch-tag.el | 2 ++
> emacs/notmuch.el | 6 ++++--
> 2 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/emacs/notmuch-tag.el b/emacs/notmuch-tag.el
> index 07c260e..f54aa9d 100644
> --- a/emacs/notmuch-tag.el
> +++ b/emacs/notmuch-tag.el
> @@ -387,6 +387,8 @@ (defun notmuch-tag (query tag-changes)
> (unless (string-match-p "^[-+]\\S-+$" tag-change)
> (error "Tag must be of the form `+this_tag' or `-that_tag'")))
> tag-changes)
> + (unless query
> + (error "Nothing to tag!"))
> (unless (null tag-changes)
> (run-hooks 'notmuch-before-tag-hook)
> (if (<= (length query) notmuch-tag-argument-limit)
> diff --git a/emacs/notmuch.el b/emacs/notmuch.el
> index 6c0bc1b..1adea9c 100644
> --- a/emacs/notmuch.el
> +++ b/emacs/notmuch.el
> @@ -428,14 +428,16 @@ (defun notmuch-search-find-stable-query-region (beg end &optional only-matched)
> "Return the stable query for the current region.
>
> If ONLY-MATCHED is non-nil, include only matched messages. If it
> -is nil, include both matched and unmatched messages."
> +is nil, include both matched and unmatched messages. If there are
> +no messages in the region then return nil."
> (let ((query-list nil) (all (not only-matched)))
> (dolist (queries (notmuch-search-properties-in-region :query beg end))
> (when (first queries)
> (push (first queries) query-list))
> (when (and all (second queries))
> (push (second queries) query-list)))
> - (concat "(" (mapconcat 'identity query-list ") or (") ")")))
> + (when query-list
> + (concat "(" (mapconcat 'identity query-list ") or (") ")"))))
>
> (defun notmuch-search-find-authors ()
> "Return the authors for the current thread"
> --
> 1.7.10.4
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 310 bytes
Desc: not available
URL: <http://notmuchmail.org/pipermail/notmuch/attachments/20140521/c1a9bf26/attachment.pgp>
More information about the notmuch
mailing list