From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by olra.theworths.org (Postfix) with ESMTP id 10D9A431FAF for ; Tue, 14 Jan 2014 05:22:25 -0800 (PST) X-Virus-Scanned: Debian amavisd-new at olra.theworths.org X-Spam-Flag: NO X-Spam-Score: 0 X-Spam-Level: X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none] autolearn=disabled Received: from olra.theworths.org ([127.0.0.1]) by localhost (olra.theworths.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id v-ttB9gRtSrc for ; Tue, 14 Jan 2014 05:22:17 -0800 (PST) Received: from yantan.tethera.net (yantan.tethera.net [199.188.72.155]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) by olra.theworths.org (Postfix) with ESMTPS id 2421B431FAE for ; Tue, 14 Jan 2014 05:22:17 -0800 (PST) Received: from remotemail by yantan.tethera.net with local (Exim 4.80) (envelope-from ) id 1W33wY-0006l2-6M; Tue, 14 Jan 2014 09:22:10 -0400 Received: (nullmailer pid 27441 invoked by uid 1000); Tue, 14 Jan 2014 13:22:06 -0000 From: David Bremner To: Jani Nikula , Austin Clements Subject: Re: [PATCH 2/2] lib: introduce notmuch_database_new for initializing a database handle In-Reply-To: <87mwkf40x5.fsf@nikula.org> References: <20131204231113.GD8854@mit.edu> <87mwkf40x5.fsf@nikula.org> User-Agent: Notmuch/0.17 (http://notmuchmail.org) Emacs/24.3.1 (x86_64-pc-linux-gnu) Date: Tue, 14 Jan 2014 09:22:06 -0400 Message-ID: <87a9eyk8ap.fsf@zancas.localnet> MIME-Version: 1.0 Content-Type: text/plain Cc: notmuch@notmuchmail.org X-BeenThere: notmuch@notmuchmail.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jan 2014 13:22:25 -0000 Jani Nikula writes: >> Austin Wrote: >> >> Orthogonally -- and this may be a complete pipe dream of mine -- if we >> just had a way to return more detailed error information than a simple >> error code from notmuch_database_{create,open}, I think we wouldn't >> need any of this. Everything that these functions currently log >> (modulo one warning) is error details, so if we could return the error >> details *with the error* or somehow make them accessible, we wouldn't >> need a logger at this point (or at several other points in the >> library). > > Agreed. I tried to look into this earlier, but was hitting dead ends > *if* we want to keep reporting user friendly error status in > open/create. Obviously any concrete suggestions would be most welcome! > I'm not sure if this is also a dead end, but I was trying to sketch out an api that returned something more detailed as status and came up with the following. The general idea is to replace notmuch_status_t with a pointer to struct. This will require pretty noisy source changes, unless we're comfortable with using NULL pointer to indicate success. In either case we'd rename the existing enum to something like notmuch_status_code_t. /* pseudo-C follows */ typedef struct notmuch_status_struct * notmuch_status_t; /* we can just tell external users to pass NULL as the first argument */ notmuch_status_t notmuch_status_new (void *ctx, size_t bufsiz); void notmuch_error_destroy (notuch_error_desc_t *victim); /* printf equivalent */ notmuch_status_t *notmuch_status_format(notmuch_status_t dest, notmuch_status_code_t code, const char *format, ...); /* case 1, caller allocates */ status = notmuch_status_new (BUFSIZ); if (!status) { halt_and_catch_fire(); } /* open could continue to return notmuch_status_code_t, or just 0/1 */ if (notmuch_database_open (notmuch_config_get_database_path (config), NOTMUCH_DATABASE_MODE_READ_WRITE, ¬much, status)) { fprintf (stderr, "oops: %s\n", notmuch_status_to_string (status)); notmuch_error_destroy(error_details); return 1; } /* case 2, callee allocates */ status = notmuch_message_freeze (message); if (notmuch_status_to_code (status)) { /* every check needs to be changed, unless NULL=OK */ message_error (message, status, "freezing message"); return status; } /* some existing code is left alone */ fprintf (stderr, "Message-ID: %s\n", notmuch_message_get_message_id (message)); fprintf (stderr, "Status: %s\n", notmuch_status_to_string (status));