emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/xeft 4f16722a47 38/55: Handle database errors


From: ELPA Syncer
Subject: [elpa] externals/xeft 4f16722a47 38/55: Handle database errors
Date: Fri, 13 Jan 2023 23:58:39 -0500 (EST)

branch: externals/xeft
commit 4f16722a477d65592677a7446c1367511f0d5af2
Author: Yuan Fu <casouri@gmail.com>
Commit: Yuan Fu <casouri@gmail.com>

    Handle database errors
    
    * module/xapian-lite.cc: Update xapian-lite.
    * xeft.el (xeft--after-save, xeft-full-reindex): Handle and print
    explanation for database lock and corrupt error.
---
 module/xapian-lite.cc | 16 ++++++++++++++++
 xeft.el               | 16 +++++++++++++---
 2 files changed, 29 insertions(+), 3 deletions(-)

diff --git a/module/xapian-lite.cc b/module/xapian-lite.cc
index 2b48aefa7b..0b85ceaeb4 100644
--- a/module/xapian-lite.cc
+++ b/module/xapian-lite.cc
@@ -305,6 +305,18 @@ Fxapian_lite_reindex_file
                            "Cannot open the file");
       return NULL;
     }
+  catch (Xapian::DatabaseCorruptError &e)
+    {
+      emp_signal_message1 (env, "xapian-lite-database-corrupt-error",
+                           e.get_description().c_str());
+      return NULL;
+    }
+  catch (Xapian::DatabaseLockError &e)
+    {
+      emp_signal_message1 (env, "xapian-lite-database-lock-error",
+                           e.get_description().c_str());
+      return NULL;
+    }
   catch (Xapian::Error &e)
     {
       emp_signal_message1 (env, "xapian-lite-lib-error",
@@ -414,6 +426,10 @@ emacs_module_init (struct emacs_runtime *ert) 
EMACS_NOEXCEPT
                 "Generic xapian-lite error", "error");
   emp_define_error (env, "xapian-lite-lib-error",
                 "Xapian library error", "xapian-lite-error");
+  emp_define_error (env, "xapian-lite-database-corrupt-error",
+                "Xapian library error", "xapian-lite-lib-error");
+  emp_define_error (env, "xapian-lite-database-lock-error",
+                "Xapian library error", "xapian-lite-lib-error");
   emp_define_error (env, "xapian-lite-file-error",
                 "Cannot open file", "xapian-lite-error");
 
diff --git a/xeft.el b/xeft.el
index bf2632afca..5bc89d4bc1 100644
--- a/xeft.el
+++ b/xeft.el
@@ -183,7 +183,12 @@ Xeft doesn’t follow symlinks and ignores inaccessible 
directories."
 
 (defun xeft--after-save ()
   "Reindex the file."
-  (xapian-lite-reindex-file (buffer-file-name) xeft-database))
+  (condition-case _
+      (xapian-lite-reindex-file (buffer-file-name) xeft-database)
+    (xapian-lite-database-lock-error
+     (message "The Xeft database is locked (maybe there is another Xeft 
instance running) so we will skip indexing this file for now"))
+    (xapian-lite-database-corrupt-error
+     (message "The Xeft database is corrupted! You should delete the database 
and Xeft will recreate it. Make sure other programs are not messing with Xeft 
database"))))
 
 (defvar xeft-mode-map
   (let ((map (make-sparse-keymap)))
@@ -328,8 +333,13 @@ Xeft doesn’t follow symlinks and ignores inaccessible 
directories."
 (defun xeft-full-reindex ()
   "Do a full reindex of all files."
   (interactive)
-  (dolist (file (xeft--file-list))
-    (xapian-lite-reindex-file file xeft-database)))
+  (condition-case _
+      (dolist (file (xeft--file-list))
+        (xapian-lite-reindex-file file xeft-database))
+    (xapian-lite-database-lock-error
+     (message "The Xeft database is locked (maybe there is another Xeft 
instance running) so we will skip indexing for now"))
+    (xapian-lite-database-corrupt-error
+     (message "The Xeft database is corrupted! You should delete the database 
and Xeft will recreate it. Make sure other programs are not messing with Xeft 
database"))))
 
 ;;; Draw
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]