From: David Bremner <david@tethera.net>
To: Jani Nikula <jani@nikula.org>, Austin Clements <amdragon@MIT.EDU>
Cc: notmuch@notmuchmail.org
Subject: Re: [PATCH 2/2] lib: introduce notmuch_database_new for initializing a database handle
Date: Tue, 14 Jan 2014 09:22:06 -0400 [thread overview]
Message-ID: <87a9eyk8ap.fsf@zancas.localnet> (raw)
In-Reply-To: <87mwkf40x5.fsf@nikula.org>
Jani Nikula <jani@nikula.org> 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));
next prev parent reply other threads:[~2014-01-14 13:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-01 13:13 [PATCH 0/2] lib: introduce notmuch_database_new Jani Nikula
2013-12-01 13:13 ` [PATCH 1/2] lib: add return status to database close and destroy Jani Nikula
2013-12-04 16:31 ` Austin Clements
2013-12-04 18:40 ` Jani Nikula
2013-12-01 13:14 ` [PATCH 2/2] lib: introduce notmuch_database_new for initializing a database handle Jani Nikula
2013-12-03 11:47 ` David Bremner
2013-12-03 14:11 ` Tomi Ollila
2013-12-03 17:29 ` Jani Nikula
2013-12-03 19:35 ` Tomi Ollila
2013-12-03 17:22 ` Jani Nikula
2013-12-04 23:11 ` Austin Clements
2013-12-05 18:17 ` Jani Nikula
2014-01-14 13:22 ` David Bremner [this message]
2014-01-15 14:19 ` David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87a9eyk8ap.fsf@zancas.localnet \
--to=david@tethera.net \
--cc=amdragon@MIT.EDU \
--cc=jani@nikula.org \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).