Subject: bug#47642: 28.0.50; (error "Selection owner couldn't convert" UTF8_STRING)

From: Juri Linkov <[email-masked]>
Date: Mon, 12 Apr 2021 19:03:48 +0300

>> after copying an image in Gimp, then exiting Gimp, and trying to paste
>> in Emacs.
>
> I was unable to reproduce that (on Debian/bullseye) -- I just get nil
> back from
>
> (x-get-selection-internal 'CLIPBOARD 'UTF8_STRING nil nil)
>
> no matter whether Gimp is running or not (after choosing Edit -> Copy).

Here is a complete test case with 100% reproducibility:

1. In GIMP 2.10.18 on Ubuntu create a new image
2. Select a rectangle
3. Copy with Ctrl+C or Edit -> Copy

4. in 'emacs -Q' version 28, GTK+ version 3.24.20
5. evaluating (x-get-selection-internal 'CLIPBOARD 'UTF8_STRING nil nil)
   returns nil

6. quit Gimp
7. evaluate the same (x-get-selection-internal 'CLIPBOARD 'UTF8_STRING nil nil)
8. it fails with

Debugger entered--Lisp error: (error "Selection owner couldn't convert" UTF8_STRING)
  x-get-selection-internal(CLIPBOARD UTF8_STRING nil nil)
  (progn (x-get-selection-internal 'CLIPBOARD 'UTF8_STRING nil nil))
  eval((progn (x-get-selection-internal 'CLIPBOARD 'UTF8_STRING nil nil)) t)
  elisp--eval-last-sexp(nil)
  eval-last-sexp(nil)
  funcall-interactively(eval-last-sexp nil)
  call-interactively(eval-last-sexp nil nil)
  command-execute(eval-last-sexp)

This is strange since there is no owner anymore, the selection owner was closed.

It's a big problem for me because I customized
save-interprogram-paste-before-kill to t, and I can't
use copy/paste in Emacs anymore after this error,
because I raises the same error on trying to copy a new text,
so even can't overwrite the old unavailable selection
with a new one in Emacs.  Then I need to switch to
some other app, copy some text from it to the clipboard,
that fixes the broken state of copy/paste in Emacs.

> In any case -- I'm not sure there's anything we can do on the Emacs
> side...  except perhaps change the error message?  "Couldn't convert"
> isn't really informative.  "Couldn't get selection from selection
> owner", perhaps?

I wonder why this error should be raised at all
instead of just returning nil?