djcb / mu

maildir indexer/searcher + emacs mail client + guile bindings
http://www.djcbsoftware.nl/code/mu
GNU General Public License v3.0
1.62k stars 391 forks source link

[mu4e bug] headers-truncate wrong-type-argument number-or-marker-p nil #2754

Closed kepi closed 2 months ago

kepi commented 2 months ago

Describe the bug

When displaying headers view, rendering stops on error and I can't access all my e-mails.

How to Reproduce

I believe this is related to specific message but wasn't successful in pinpointing which one yet. TBH I can't get head or tails from debugger info.

Environment

Arch Linux with mu 1.12.6, Doom Emacs.

Checklist

Again, TBH I didn't try to reproduce with minimal environment, but I pinpointed the problem to specific place in code, so I hope it is worth your time. If not, just let me know and I'll try to do this later, but I already spent too much time on this and can't promise I'll get to this.

Debugger output

Debugger entered--Lisp error: (wrong-type-argument number-or-marker-p nil)
  truncate-string-to-width(#("    " 0 1 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 1 2 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t) 2 3 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 3 4 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t) 4 5 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 5 6 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8 :inherit nerd-icons-silver) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8 :inherit nerd-icons-silver) display (raise 0.02) rear-nonsticky t) 6 7 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 7 8 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t)) 6 0 32 " [...] ")
  (if width (truncate-string-to-width val width 0 32 truncate-string-ellipsis) val)
  mu4e~headers-truncate-field-fast(#("    " 0 1 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 1 2 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t) 2 3 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 3 4 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t) 4 5 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 5 6 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8 :inherit nerd-icons-silver) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8 :inherit nerd-icons-silver) display (raise 0.02) rear-nonsticky t) 6 7 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 7 8 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t)) 6)
  (if mu4e-headers-precise-alignment (mu4e~headers-truncate-field-precise field val width) (mu4e~headers-truncate-field-fast val width))
  mu4e~headers-truncate-field(:flags #("    " 0 1 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 1 2 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t) 2 3 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 3 4 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t) 4 5 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 5 6 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8 :inherit nerd-icons-silver) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8 :inherit nerd-icons-silver) display (raise 0.02) rear-nonsticky t) 6 7 (help-echo "(flagged replied seen attach personal)" display (space :width 0.75)) 7 8 (help-echo "(flagged replied seen attach personal)" face (:family "Symbols Nerd Font Mono" :height 0.8) font-lock-face (:family "Symbols Nerd Font Mono" :height 0.8) display (raise 0.02) rear-nonsticky t)) 6)
  (if width (mu4e~headers-truncate-field field val width) val)
  (and val (if width (mu4e~headers-truncate-field field val width) val))
  (let* ((field (car f-w)) (width (cdr f-w)) (val (mu4e~headers-field-value msg field)) (val (and val (if width (mu4e~headers-truncate-field field val width) val)))) val)
  mu4e~headers-field-handler((:flags . 6) (:path "/home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS" :size 279322 :cc ((:email "kepi@some.domain")) :changed (26320 43895 0) :date (26320 34088 0) :from ((:email "noreply@some.domain" :name "some.domain")) :message-id "zwb1fhUO6gA5nmfiedp1nvJykJJQ0ZrxfVHh4gHd2I@posilator.some.domain" :priority normal :subject "redacted" :to ((:email "prace@some.domain")) :maildir "/kepi/INBOX" :flags (flagged replied seen attach personal) :docid 193214 :meta (:path "04" :level 0 :date "n66d0ab76" :data-tstamp (0 0 0) :root t :has-child t :thread-subject t)))
  #f(lambda (f-w) [(msg (:path "/home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS" :size 279322 :cc ((:email "kepi@some.domain")) :changed (26320 43895 0) :date (26320 34088 0) :from ((:email "noreply@some.domain" :name "some.domain")) :message-id "zwb1fhUO6gA5nmfiedp1nvJykJJQ0ZrxfVHh4gHd2I@posilator.some.domain" :priority normal :subject "redacted 2" :to ((:email "prace@some.domain")) :maildir "/kepi/INBOX" :flags (flagged replied seen attach personal) :docid 193214 :meta (:path "04" :level 0 :date "n66d0ab76" :data-tstamp (0 0 0) :root t :has-child t :thread-subject t)))] (mu4e~headers-field-handler f-w msg))((:flags . 6))
  mapconcat(#f(lambda (f-w) [(msg (:path "/home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS" :size 279322 :cc ((:email "kepi@some.domain")) :changed (26320 43895 0) :date (26320 34088 0) :from ((:email "noreply@some.domain" :name "some.domain")) :message-id "zwb1fhUO6gA5nmfiedp1nvJykJJQ0ZrxfVHh4gHd2I@posilator.some.domain" :priority normal :subject "redacted 2" :to ((:email "prace@some.domain")) :maildir "/kepi/INBOX" :flags (flagged replied seen attach personal) :docid 193214 :meta (:path "04" :level 0 :date "n66d0ab76" :data-tstamp (0 0 0) :root t :has-child t :thread-subject t)))] (mu4e~headers-field-handler f-w msg)) ((:account-stripe . 1) (:human-date . 12) (:flags . 6) (:from-or-to . 25) (:subject)) " ")
  (mu4e~headers-apply-flags msg (mapconcat #'(lambda (f-w) (mu4e~headers-field-handler f-w msg)) mu4e-headers-fields " "))
  (progn (mu4e~headers-apply-flags msg (mapconcat #'(lambda (f-w) (mu4e~headers-field-handler f-w msg)) mu4e-headers-fields " ")))
  (if (and mu4e-search-hide-enabled mu4e-search-hide-predicate (funcall mu4e-search-hide-predicate msg)) (progn (setq mu4e~headers-hidden (1+ mu4e~headers-hidden)) nil) (progn (mu4e~headers-apply-flags msg (mapconcat #'(lambda (f-w) (mu4e~headers-field-handler f-w msg)) mu4e-headers-fields " "))))
  mu4e~message-header-line((:path "/home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS" :size 279322 :cc ((:email "kepi@some.domain")) :changed (26320 43895 0) :date (26320 34088 0) :from ((:email "noreply@some.domain" :name "some.domain")) :message-id "zwb1fhUO6gA5nmfiedp1nvJykJJQ0ZrxfVHh4gHd2I@posilator.some.domain" :priority normal :subject "redacted 2" :to ((:email "prace@some.domain")) :maildir "/kepi/INBOX" :flags (flagged replied seen attach personal) :docid 193214 :meta (:path "04" :level 0 :date "n66d0ab76" :data-tstamp (0 0 0) :root t :has-child t :thread-subject t)))
  (and t (mu4e~message-header-line msg))
  (let* ((line (and t (mu4e~message-header-line msg))) (docid (and line (plist-get msg :docid)))) (if docid (progn (goto-char pos) (insert (propertize (concat (mu4e~headers-docid-cookie docid) mu4e--mark-fringe line "\n") 'docid docid 'msg msg))) nil))
  mu4e~headers-insert-header((:path "/home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS" :size 279322 :cc ((:email "kepi@some.domain")) :changed (26320 43895 0) :date (26320 34088 0) :from ((:email "noreply@some.domain" :name "some.domain")) :message-id "zwb1fhUO6gA5nmfiedp1nvJykJJQ0ZrxfVHh4gHd2I@posilator.some.domain" :priority normal :subject "redacted 2" :to ((:email "prace@some.domain")) :maildir "/kepi/INBOX" :flags (flagged replied seen attach personal) :docid 193214 :meta (:path "04" :level 0 :date "n66d0ab76" :data-tstamp (0 0 0) :root t :has-child t :thread-subject t)) 356)
  #f(lambda (msg) [t] (mu4e~headers-insert-header msg (point-max)))((:path "/home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS" :size 279322 :cc ((:email "kepi@some.domain")) :changed (26320 43895 0) :date (26320 34088 0) :from ((:email "noreply@some.domain" :name "some.domain")) :message-id "zwb1fhUO6gA5nmfiedp1nvJykJJQ0ZrxfVHh4gHd2I@posilator.some.domain" :priority normal :subject "redacted 2" :to ((:email "prace@some.domain")) :maildir "/kepi/INBOX" :flags (flagged replied seen attach personal) :docid 193214 :meta (:path "04" :level 0 :date "n66d0ab76" :data-tstamp (0 0 0) :root t :has-child t :thread-subject t)))
  mapc(#f(lambda (msg) ... ...) (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  seq-do(#f(lambda (msg) ... ...) (... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  (let ((inhibit-read-only t)) (seq-do #'(lambda (msg) (mu4e~headers-insert-header msg (point-max))) msglst))
  (save-excursion (let ((inhibit-read-only t)) (seq-do #'(lambda (msg) (mu4e~headers-insert-header msg (point-max))) msglst)))
  (save-current-buffer (set-buffer (mu4e-get-headers-buffer)) (save-excursion (let ((inhibit-read-only t)) (seq-do #'(lambda (msg) (mu4e~headers-insert-header msg (point-max))) msglst))))
  (progn (save-current-buffer (set-buffer (mu4e-get-headers-buffer)) (save-excursion (let ((inhibit-read-only t)) (seq-do #'(lambda (msg) (mu4e~headers-insert-header msg ...)) msglst)))))
  (if (buffer-live-p (mu4e-get-headers-buffer)) (progn (save-current-buffer (set-buffer (mu4e-get-headers-buffer)) (save-excursion (let ((inhibit-read-only t)) (seq-do #'(lambda ... ...) msglst))))))
  mu4e~headers-append-handler((... ... ... ... ... ... ... ... ... ... ... ... ... ... ...))
  mu4e--server-filter(#<process  *mu4e-server*> "ubject \"[Z\303\241kaznick\303\241 podpora - Podpora #125181] akdrozd.cz - p\305\231esm\304\233rov\303\241n\303\255 dom\303\251ny\" :maildir \"/kepi/INBOX\" :docid 193374 :meta (:path \"5b:01\" :level 1 :date \"n66d6c6f1\" :data-tstamp (0 0 0) :last-child t :orphan t :thread-subject t))\n(:path \"/home/kepi/Maily/kepi/INBOX/new/1725355767.3030023_8.kocour,U=3474:2,\" :size 14441 :changed (26326 55031 0) :date (26326 51006 0) :from ((:email \"p@different.domain\" :name \"somebody")) :message-id \"m0m5si7f.d883baad-50a6-40d7-b2d1-aad1fb83a147@we.are.superhuman.com\" :priority normal :subject \"redacted 3\" :to ((:email \"kepi@some.domain\" :name \"kepi@some.domain\") (:email \"somebody@some.domain\" :name \"else\") (:email \"anybody@some.domain\" :name \"anybody@some.domain\")) :maildir \"/kepi/INBOX\" :flags (new unread personal) :docid 193373 :meta (:path \"5c\" :level 0 :date \"n66d6c73e\" :data-tstamp (0 0 0) :root t :thread-subject t))\n(:path \"/home/kepi/Maily/kepi/INBOX/new/1725356098.3035527_1.kocour,U=3475:2,\" :size 27768 :changed (26326 55362 0) :date (26326 55357 0) :from ((:email \"noreply@github.com\" :name \"GitHub\")) :list \"\" :message-id \"66d6d83dd5922_b36be1ce815679@github-lowworker-5e49b88.va3-iad.github.net.mail\" :priority normal :subject \"[GitHub] Your Dependabot alerts for the week of Aug 27 - Sep 3\" :to ((:email \"kepi@some.domain\" :name \"Kepi\")) :maildir \"/kepi/INBOX\" :flags (new unread list personal) :docid 193376 :meta (:path \"5d\" :level 0 :date \"n66d6d83d\" :data-tstamp (0 0 0) :root t :thread-subject t))\n))\n\376d\377(:found 104)\n;; mu> ")

My workaround

Disclamier: I have only really basic understanding of emacs lisp, no practical knowledge, so I just tried to mess around.

I tried to add some (or... to the function, but no success. I tried to strip properties from text and then using or, but I still get the error.

(defsubst mu4e~headers-truncate-field-fast (val width)
  "Truncate VAL to WIDTH. Fast and somewhat inaccurate."
  (if width
      (truncate-string-to-width val width 0 ?\s truncate-string-ellipsis)
    val))

When replacing val in truncate-string-to-width with "", it loads OK (but with empty fields ofc). But, when leaving val in place and replacing width with 10 or higher number, it works fine again.

I really don't understand how exactly string formatting works, if it is related to that or something else. I would like to dig into this more but I know I wont find more time anytime soon.

I can definitely test any workaround or fix if you can give me some tips what to try. I'm backing up current INBOX so I can test this later if needed.

Edit: btw same problem is ofc when using precise truncating.

djcb commented 2 months ago

Did you customize any of the headers marks (ie. mu4e-headers-*mark). If so, perhaps try the defaults; it might be that your font is missing some character? That would be my working hypothesis

Guess it would be the message /home/kepi/Maily/kepi/INBOX/cur/1724941611.2253101_1.kocour,U=3349:2,FRS ?

Thanks.

kepi commented 2 months ago

Yes you are right. I already found duplicate of that one as culprit of the problem, and this one is causing problem too.

And you are ofc correct that it is probably some symbol. I'm not customizing any header marks and neither can I find anything related in Doom's mu4e module, but when I realized my config should work even without Doom module, I tested it and it is working.

There are definitely some fancy unicode characters in flags field instead of text ones in plain mu4e.

I still didn't find exact place where this is happening, but I'll figure it hopefully on my own and report to Doom if needed.

I'm not sure, if there isn't some nice workaround to handle such error? It would be great if flags simply won't display for that problematic message. I'm not sure if there is something like try/catch in elisp which will return either original val or empty string when truncate string would return error otherwise? Feel free to close this issue if it is wrong way to handle things or you simply don't want to do that.

Thanks!

kepi commented 2 months ago

and just found it... probably missing nf-fa-flag nerd icon, which is weird, as I also tried installing nerd fonts from emacs and flagged messages worked before... Looks like problem in my installation anyway.

For now, I just commented mu4e-headers-flagged-mark modification in modules/email/mu4e/autoload/email.el.

I'm still leaving the decision if you want to handle such cases or not to you. Thanks for help.

djcb commented 2 months ago

Mu4e also has some "fancy" (well, non-ascii) characters, but it's rather conservative, so less likely to have problems.

It's not too hard to wrap the function in (ignore-errors ...) etc., but that would merely hide the bug. Perhaps Emacs itself would be a better place to raise a bit more readable error "Cannot find glyph" and/or some workaround.

Anyway, thanks for clearing this up; I'm closing this, don't think there's a lot to do for mu4e here.