From e07972cffb19b667ed7d5e42b6f0ba4423f1ac86 Mon Sep 17 00:00:00 2001 From: Brandon Orther Date: Mon, 14 Aug 2017 23:37:17 -0700 Subject: [PATCH] Gracefully handle +ivy-tasks match errors When trying to use +ivy-tasks in one of my projects it was failing w/ error: `(Stack overflow in regexp matcher)`. This was due to ripgrep searching a folder in the project root containing a minified bootstrap CSS source map file (which had a `TODO:` in it). Since that file was a single line of text concatenated together, the regex was getting passed ~540KB of text. To make it easier to recognize what is causing +ivy-tasks to fail I wrapped the failing code in `condition-case-unless-debug` and report the error and the file causing the error using `message!`. So now if there is a failure during the extraction of task from the search cmd's results it moves onto the next and alerts the user in separate pop-up. To avoid including the bootstrap file in the ripgrep search result, I added a `.ignore` file to the project that tells `rg` to ignore it. NOTE: I was surprised that this problem file was include in the ivy-tasks search because I expected the search to respect projectile ignore settings. Respecting projectile's ignored/unignored files and directories wouldn't be too difficult considering projectile provides a robust collection of functions to help support this. Also projectile's `projectile-ag` function is a great reference. --- modules/completion/ivy/autoload/ivy.el | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/modules/completion/ivy/autoload/ivy.el b/modules/completion/ivy/autoload/ivy.el index 944741053..adb6dcf11 100644 --- a/modules/completion/ivy/autoload/ivy.el +++ b/modules/completion/ivy/autoload/ivy.el @@ -110,11 +110,17 @@ If WORKSPACE-ONLY-P (universal arg), limit to buffers in the current workspace." (save-match-data (cl-loop with out = (shell-command-to-string cmd) for x in (and out (split-string out "\n" t)) - when (string-match - (concat "^\\([^:]+\\):\\([0-9]+\\):.+\\(" - (string-join task-tags "\\|") - "\\):?\\s-*\\(.+\\)") - x) + when (condition-case-unless-debug ex + (string-match + (concat "^\\([^:]+\\):\\([0-9]+\\):.+\\(" + (string-join task-tags "\\|") + "\\):?\\s-*\\(.+\\)") + x) + (error + (message! (red "Error matching task in file: (%s) %s" + (error-message-string ex) + (car (split-string x ":")))) + nil)) collect `((type . ,(match-string 3 x)) (desc . ,(match-string 4 x)) (file . ,(match-string 1 x))