Re: [BUG] "Not enough arguments for format string" from failed fuzzy search containing % [9.6.19]

2024-02-25 Thread Ihor Radchenko
"Corwin Kerr"  writes:

> When a search link with a fuzzy expression contains the % character
> and is not found in the file, the error message is burried by format
> error. This affects ~org-link-search~, ~org-open-file~, etc.
>
> Expected message:
> : No match for fuzzy expression: % search bad
> Actual message:
> : Not enough arguments for format string
> ...
> * Minimal reproduction

Thanks for reporting!
Fixed, on main.
https://git.savannah.gnu.org/cgit/emacs/org-mode.git/commit/?id=af9100382

-- 
Ihor Radchenko // yantar92,
Org mode contributor,
Learn more about Org mode at .
Support Org development at ,
or support my work at 



[BUG] "Not enough arguments for format string" from failed fuzzy search containing % [9.6.19]

2024-02-24 Thread Corwin Kerr
Hello,

When a search link with a fuzzy expression contains the % character
and is not found in the file, the error message is burried by format
error. This affects ~org-link-search~, ~org-open-file~, etc.

Expected message:
: No match for fuzzy expression: % search bad
Actual message:
: Not enough arguments for format string

I ended up with this search term by storing a link to a comment in a tex file.

Here is the backtrace from how I originally discovered it:
#+begin_src elisp
  Debugger entered--Lisp error: (error "Not enough arguments for format string")
  format-message("No match for fuzzy expression: % search bad")
  apply(format-message "No match for fuzzy expression: % search bad")
  error("No match for fuzzy expression: % search bad")
  org-open-file(".../bad-file.tex" nil nil "% search bad")
  apply(org-open-file ".../bad-file.tex" nil (nil "% search bad"))
  org-link-open-as-file(".../bad-file.tex::% how thi..." nil)
  org-link-open((link (:type "file" :path ".../bad-file.tex" :format bracket 
:raw-link "file:.../bad-file.tex::% ho..." :application nil :search-option "% 
search bad" :begin 8347 :end 8450 :contents-begin 8432 :contents-end 8447 
:post-blank 1 :parent (paragraph (:begin 8347 :end 8461 :contents-begin 8347 
:contents-end 8460 :post-blank 1 :post-affiliated 8347 :mode nil :granularity 
element :cached t :parent (section (:begin 8312 :end 8461 :contents-begin 8312 
:contents-end 8460 :robust-begin 8312 :robust-end 8458 :post-blank 1 
:post-affiliated 8312 :mode section :granularity element :cached t :parent 
(headline ...) :org-element--cache-sync-key nil)) :org-element--cache-sync-key 
nil nil)
  org-open-at-point()
  org-open-at-mouse((mouse-2 (# 8438 (138 . 355) 
272166805 nil 8438 (14 . 16) nil (5 . 5) (11 . 22
  funcall-interactively(org-open-at-mouse (mouse-2 (# 
8438 (138 . 355) 272166805 nil 8438 (14 . 16) nil (5 . 5) (11 . 22
  call-interactively(org-open-at-mouse nil nil)
  command-execute(org-open-at-mouse)
#+end_src

* Versions
GNU Emacs 28.2 (build 1, x86_64-apple-darwin18.7.0, NS appkit-1671.60 Version 
10.14.6 (Build 18G95)) of 2023-02-22
Org mode version 9.6.19 (release_9.6.19 @ 
/Users/Corwin/.emacs.d/straight/repos/org/lisp/)

* Minimal reproduction
#+begin_src tex :tangle bad-file.tex
  \begin{document}
  % search attempt
  \end{document}
#+end_src

#+begin_src elisp :tangle minimal.el
  (setq debug-on-error t
debug-on-signal nil
debug-on-quit nil)

  ;; Add latest Org mode to load path.
  (add-to-list 'load-path (expand-file-name 
"~/.emacs.d/straight/repos/org/lisp"))
  
  (org-open-file "bad-file.tex" nil nil "% search attempt") ;; works
  (org-open-file "bad-file.tex" nil nil "% search bad") ;; error
#+end_src

Running emacs with
: /Applications/Emacs.app/Contents/MacOS/Emacs -Q -l /path/to/minimal.el

Generates this backtrace:
#+begin_src elisp
  Debugger entered--Lisp error: (error "Not enough arguments for format string")
  format-message("No match for fuzzy expression: % search bad")
  apply(format-message "No match for fuzzy expression: % search bad")
  error("No match for fuzzy expression: % search bad")
  (condition-case err (org-link-search search) (error (funcall 
save-position-maybe) (error (nth 1 err
  (cond (line (org-goto-line line) (if (derived-mode-p 'org-mode) (progn 
(org-fold-reveal (search (condition-case err (org-link-search search) 
(error (funcall save-position-maybe) (error (nth 1 err))
  (cond ((org-string-nw-p cmd) (setq cmd (org--open-file-format-command cmd 
file link link-match-data)) (let ((wconfig (current-window-configuration))) 
(unwind-protect (progn (message "Running %s...done" cmd) (let 
((process-connection-type nil)) (start-process-shell-command cmd nil cmd)) (and 
(boundp 'org-wait) (numberp org-wait) (sit-for org-wait))) 
(set-window-configuration wconfig ((or (stringp cmd) (eq cmd 'emacs)) 
(funcall (cdr (assq 'file org-link-frame-setup)) file) (widen) (cond (line 
(org-goto-line line) (if (derived-mode-p 'org-mode) (progn (org-fold-reveal 
(search (condition-case err (org-link-search search) (error (funcall 
save-position-maybe) (error (nth 1 err))) ((functionp cmd) (let 
((save-match-data-internal (match-data))) (unwind-protect (progn 
(set-match-data link-match-data) (condition-case nil (funcall cmd file link) 
((debug wrong-number-of-arguments wrong-type-argument invalid-function) 
(user-error "Please see Org News for version 9.0 about `org-fil..." cmd 
(set-match-data save-match-data-internal 'evaporate ((consp cmd) 
(user-error "Please see Org News for version 9.0 about `org-fil..." cmd)) (t 
(funcall (cdr (assq 'file org-link-frame-setup)) file)))
  (let* ((file (if (equal path "") buffer-file-name (substitute-in-file-name 
(expand-file-name path (file-apps (append org-file-apps 
(org--file-default-apps))) (apps (cl-remove-if #'org--file-apps-entry-locator-p 
file-apps)) (apps-locator (cl-remove-if-not #'org--file-apps-entry-locator-p 
file-apps))