--- /dev/null
+Return-Path: <bremner@tesseract.cs.unb.ca>\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 CE02A6DE1502\r
+ for <notmuch@notmuchmail.org>; Sun, 7 Jun 2015 08:05:21 -0700 (PDT)\r
+X-Virus-Scanned: Debian amavisd-new at cworth.org\r
+X-Spam-Flag: NO\r
+X-Spam-Score: 0.219\r
+X-Spam-Level: \r
+X-Spam-Status: No, score=0.219 tagged_above=-999 required=5 tests=[AWL=0.209, \r
+ T_HEADER_FROM_DIFFERENT_DOMAINS=0.01] 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 PPh9UVjqxtFE for <notmuch@notmuchmail.org>;\r
+ Sun, 7 Jun 2015 08:05:20 -0700 (PDT)\r
+Received: from mx.xen14.node3324.gplhost.com (gitolite.debian.net\r
+ [87.98.215.224])\r
+ by arlo.cworth.org (Postfix) with ESMTPS id 154076DE119C\r
+ for <notmuch@notmuchmail.org>; Sun, 7 Jun 2015 08:05:20 -0700 (PDT)\r
+Received: from remotemail by mx.xen14.node3324.gplhost.com with local (Exim\r
+ 4.80) (envelope-from <bremner@tesseract.cs.unb.ca>)\r
+ id 1Z1c7q-0004pb-Eu; Sun, 07 Jun 2015 15:04:38 +0000\r
+Received: (nullmailer pid 7864 invoked by uid 1000); Sun, 07 Jun 2015\r
+ 15:02:11 -0000\r
+From: David Bremner <david@tethera.net>\r
+To: notmuch@notmuchmail.org\r
+Subject: [PATCH 08/10] cli: add utility routine to print error status.\r
+Date: Sun, 7 Jun 2015 17:02:01 +0200\r
+Message-Id: <1433689323-7520-9-git-send-email-david@tethera.net>\r
+X-Mailer: git-send-email 2.1.4\r
+In-Reply-To: <1433689323-7520-1-git-send-email-david@tethera.net>\r
+References: <1433689323-7520-1-git-send-email-david@tethera.net>\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, 07 Jun 2015 15:05:21 -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 6d54742..4de39b8 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 78680aa..0f52038 100644\r
+--- a/notmuch-client.h\r
++++ b/notmuch-client.h\r
+@@ -465,6 +465,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
+ extern const notmuch_opt_desc_t notmuch_shared_options [];\r
+ void notmuch_process_shared_options (const char* subcommand_name);\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.1.4\r
+\r