karthink / gptel

A simple LLM client for Emacs
GNU General Public License v3.0
1.04k stars 111 forks source link

Adding `gptel-end-of-response` to `gptel-post-response-functions` causes error in process sentinel #262

Closed ajgrf closed 3 months ago

ajgrf commented 3 months ago

I have (add-hook 'gptel-post-response-functions 'gptel-end-of-response) in my config, and it recently started causing an error.

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  >(nil 0)
  (if (> arg 0) #'text-property-search-forward #'text-property-search-backward)
  (let ((search (if (> arg 0) #'text-property-search-forward #'text-property-search-backward))) (let ((upper-bound (abs arg)) (counter 0)) (while (< counter upper-bound) (let ((_ counter)) (funcall search 'gptel 'response t) (if (> arg 0) (if (looking-at (concat "\n\\{1,2\\}" ... "?")) (progn (goto-char ...))) (if (looking-back (concat ... "?") (point-min)) (progn (goto-char ...))))) (setq counter (1+ counter)))))
  gptel-end-of-response(41 156)
  run-hook-with-args(gptel-end-of-response 41 156)
  gptel-curl--stream-cleanup(#<process gptel-curl> "finished\n")

I believe this was caused by recent commit 376fb4b423 which doesn't handle a nil prefix arg passed to gptel-end-of-response.

Thanks for all your hard work on gptel, I use it quite a bit!

karthink commented 3 months ago

Fixed, thank you for reporting this.