Subject: bug#29246: Possible solution?

From: Stefan Kangas <[email-masked]>
Date: Mon, 11 Nov 2019 03:17:59 +0100

Lele Gaifax <[email-masked]> writes:

> I'm trying the following, that seems to fix the issue:
>
>   (defun python--flymake-parse-output (source proc report-fn)
>     "Collect diagnostics parsing checker tool's output line by line."
>     (let ((rx (nth 0 python-flymake-command-output-pattern))
>           (lineidx (nth 1 python-flymake-command-output-pattern))
>           (colidx (nth 2 python-flymake-command-output-pattern))
>           (typeidx (nth 3 python-flymake-command-output-pattern))
>           (msgidx (nth 4 python-flymake-command-output-pattern)))
>       (with-current-buffer (process-buffer proc)
>         (goto-char (point-min))
>         (cl-loop
>          while (search-forward-regexp rx nil t)
>          for msg = (match-string msgidx)
>          for (beg . end) = (flymake-diag-region
>                             source
>                             (string-to-number
>                              (match-string lineidx))
>                             (and colidx
>                                  (match-string colidx)
>                                  (string-to-number
>                                   (match-string colidx))))
>          for type = (or (and typeidx
>                              (match-string typeidx)
>                              (assoc-default
>                               (match-string typeidx)
>                               python-flymake-msg-alist
>                               #'string-match))
>                         (assoc-default msg
>                                        python-flymake-msg-alist
>                                        #'string-match)
>                         :error)
>          if (and beg end)
>            collect (flymake-make-diagnostic
>                     source beg end type msg) into diags
>          finally (funcall report-fn diags)))))
>
> where I added an `if (and beg end)' clause around `collect'.
>
> Is that reasonable, or would it be better to make `flymake--highlight-line'
> more robust againt a diagnostic with invalid `beg'/`end' slots?

Could you please provide a recipe for how to reproduce the original
issue?  Otherwise, it's hard to test your suggested patch.

Could you also send a diff (or patch) with your suggested changes
instead of the full function?  Otherwise, it's hard to see what you
have changed.  Preferably the diff should be against the current
development version of Emacs (in git).

Thanks in advance.

Best regards,
Stefan Kangas