--- /dev/null
+Return-Path: <bremner@tethera.net>\r
+X-Original-To: notmuch@notmuchmail.org\r
+Delivered-To: notmuch@notmuchmail.org\r
+Received: from localhost (localhost [127.0.0.1])\r
+ by arlo.cworth.org (Postfix) with ESMTP id 7B2DF6DE1640\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 06:58:44 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 2.648\r
+X-Spam-Level: **\r
+X-Spam-Status: No, score=2.648 tagged_above=-999 required=5 tests=[AWL=-1.042,\r
+ RCVD_IN_BRBL_LASTEXT=1.644, RCVD_IN_SBL=2.596, RP_MATCHES_RCVD=-0.55]\r
+ autolearn=disabled\r
+Received: from arlo.cworth.org ([127.0.0.1])\r
+ by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)\r
+ with ESMTP id yqg3-669NIf3 for <notmuch@notmuchmail.org>;\r
+ Sun, 6 Sep 2015 06:58:42 -0700 (PDT)\r
+X-Greylist: delayed 2569 seconds by postgrey-1.35 at arlo;\r
+ Sun, 06 Sep 2015 06:58:42 PDT\r
+Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id B7E4D6DE1633\r
+ for <notmuch@notmuchmail.org>; Sun, 6 Sep 2015 06:58:42 -0700 (PDT)\r
+Received: from remotemail by yantan.tethera.net with local (Exim 4.80)\r
+ (envelope-from <bremner@tethera.net>)\r
+ id 1ZYZnT-0002wz-L9; Sun, 06 Sep 2015 10:15:51 -0300\r
+Received: (nullmailer pid 29725 invoked by uid 1000); Sun, 06 Sep 2015\r
+ 13:15:48 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 1/3] cli: add utility routine to print error status.\r
+Date: Sun, 6 Sep 2015 10:15:45 -0300\r
+Message-Id: <1441545347-29549-1-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.5.1\r
+X-BeenThere: notmuch@notmuchmail.org\r
+X-Mailman-Version: 2.1.18\r
+Precedence: list\r
+List-Id: "Use and development of the notmuch mail system."\r
+ <notmuch.notmuchmail.org>\r
+List-Unsubscribe: <http://notmuchmail.org/mailman/options/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>\r
+List-Archive: <http://notmuchmail.org/pipermail/notmuch/>\r
+List-Post: <mailto:notmuch@notmuchmail.org>\r
+List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>\r
+List-Subscribe: <http://notmuchmail.org/mailman/listinfo/notmuch>,\r
+ <mailto:notmuch-request@notmuchmail.org?subject=subscribe>\r
+X-List-Received-Date: Sun, 06 Sep 2015 13:58:44 -0000\r
+\r
+No attention to formatting here, initially just focus on getting the\r
+relevant strings out of the library.\r
+---\r
+ Makefile.local | 1 +\r
+ notmuch-client.h | 9 +++++++++\r
+ status.c | 21 +++++++++++++++++++++\r
+ 3 files changed, 31 insertions(+)\r
+ create mode 100644 status.c\r
+\r
+diff --git a/Makefile.local b/Makefile.local\r
+index 61a9c4c..d58cea0 100644\r
+--- a/Makefile.local\r
++++ b/Makefile.local\r
+@@ -271,6 +271,7 @@ dataclean: distclean\r
+ notmuch_client_srcs = \\r
+ command-line-arguments.c\\r
+ debugger.c \\r
++ status.c \\r
+ gmime-filter-reply.c \\r
+ hooks.c \\r
+ notmuch.c \\r
+diff --git a/notmuch-client.h b/notmuch-client.h\r
+index 882aa30..de8a3b1 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -449,6 +449,15 @@ notmuch_database_dump (notmuch_database_t *notmuch,\r
+ dump_format_t output_format,\r
+ notmuch_bool_t gzip_output);\r
+ \r
++/* If status is non-zero (i.e. error) print appropriate\r
++ messages to stderr.\r
++*/\r
++\r
++notmuch_status_t\r
++print_status_query (const char *loc,\r
++ const notmuch_query_t *query,\r
++ notmuch_status_t status);\r
++\r
+ #include "command-line-arguments.h"\r
+ \r
+ extern char *notmuch_requested_db_uuid;\r
+diff --git a/status.c b/status.c\r
+new file mode 100644\r
+index 0000000..8fa81cb\r
+--- /dev/null\r
++++ b/status.c\r
+@@ -0,0 +1,21 @@\r
++#include "notmuch-client.h"\r
++\r
++notmuch_status_t\r
++print_status_query (const char *loc,\r
++ const notmuch_query_t *query,\r
++ notmuch_status_t status)\r
++{\r
++ if (status) {\r
++ const char *msg;\r
++ notmuch_database_t *notmuch;\r
++\r
++ fprintf (stderr, "%s: %s\n", loc,\r
++ notmuch_status_to_string (status));\r
++\r
++ notmuch = notmuch_query_get_database (query);\r
++ msg = notmuch_database_status_string (notmuch);\r
++ if (msg)\r
++ fputs (msg, stderr);\r
++ }\r
++ return status;\r
++}\r
+-- \r
+2.5.1\r
+\r