File: 0002-no-config-error.patch

package info (click to toggle)
notifymuch 0.1~git20151223.0.9d4aaf5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 128 kB
  • sloc: python: 248; sh: 13; makefile: 2
file content (67 lines) | stat: -rw-r--r-- 2,377 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
Description: Expand error message for notmuch2.NoConfigError
 notifymuch fails if notmuch is not configured, i.e., notmuch's configuration is
 missing.  This patch expands the error message provided in this case.
Author: itd <itd@net.in.tum.de>

---
Forwarded: no
Last-Update: 2025-03-24

--- notifymuch-0.1~git20151223.0.9d4aaf5.orig/bin/notifymuch
+++ notifymuch-0.1~git20151223.0.9d4aaf5/bin/notifymuch
@@ -20,7 +20,12 @@ if args.print_summary:
     from notifymuch.messages import Messages
     from notifymuch import config
     config.load()
-    summary = Messages().summary()
+    try:
+        summary = Messages().summary()
+    except Messages.NoConfigError as e:
+        print('Unable to fetch notmuch messages: %s' % e, file=sys.stderr)
+        print('Is notmuch configured correctly?', file=sys.stderr)
+        sys.exit(1)
     if summary:
         print(summary)
 else:
--- notifymuch-0.1~git20151223.0.9d4aaf5.orig/notifymuch/messages.py
+++ notifymuch-0.1~git20151223.0.9d4aaf5/notifymuch/messages.py
@@ -118,8 +118,13 @@ def summary(messages):
 
 
 class Messages:
+    class NoConfigError(Exception):
+        '''Re-export of notmuch2 exception'''
     def __init__(self):
-        self.db = notmuch2.Database()
+        try:
+            self.db = notmuch2.Database()
+        except notmuch2.NoConfigError as error:
+            raise Messages.NoConfigError(error)
         self.query = lambda f: getattr(self.db, f)(
             config.get('query'),
             sort=notmuch2._database.QuerySortOrder.OLDEST_FIRST,
--- notifymuch-0.1~git20151223.0.9d4aaf5.orig/notifymuch/notification.py
+++ notifymuch-0.1~git20151223.0.9d4aaf5/notifymuch/notification.py
@@ -1,5 +1,6 @@
 import shlex
 import subprocess
+import sys
 
 import gi
 
@@ -49,8 +50,13 @@ class NotifymuchNotification(Gio.Applica
 
     def on_activate(self, data):
         config.load()  # Reload config on each update.
-        messages = Messages()
-        summary = messages.unseen_summary()
+        try:
+            messages = Messages()
+            summary = messages.unseen_summary()
+        except Messages.NoConfigError as e:
+            print('Unable to fetch notmuch messages: %s' % e, file=sys.stderr)
+            print('Is notmuch configured correctly?', file=sys.stderr)
+            sys.exit(1)
         if summary == "":
             self.release()
         else: