lib: catch exceptions in n_directory_get_child_directories

Also clarify API in error case.
This commit is contained in:
David Bremner 2020-08-01 09:25:55 -03:00
parent 919b89156c
commit 9668583a49
3 changed files with 22 additions and 4 deletions

View file

@ -49,6 +49,19 @@ struct _notmuch_directory {
time_t mtime; time_t mtime;
}; };
#define LOG_XAPIAN_EXCEPTION(directory, error) _log_xapian_exception (__location__, directory, error)
static void
_log_xapian_exception (const char *where, notmuch_directory_t *dir, const Xapian::Error error) {
notmuch_database_t *notmuch = dir->notmuch;
_notmuch_database_log (notmuch,
"A Xapian exception occurred at %s: %s\n",
where,
error.get_msg ().c_str ());
notmuch->exception_reported = true;
}
/* We end up having to call the destructor explicitly because we had /* We end up having to call the destructor explicitly because we had
* to use "placement new" in order to initialize C++ objects within a * to use "placement new" in order to initialize C++ objects within a
* block that we allocated with talloc. So C++ is making talloc * block that we allocated with talloc. So C++ is making talloc
@ -267,14 +280,18 @@ notmuch_filenames_t *
notmuch_directory_get_child_directories (notmuch_directory_t *directory) notmuch_directory_get_child_directories (notmuch_directory_t *directory)
{ {
char *term; char *term;
notmuch_filenames_t *child_directories; notmuch_filenames_t *child_directories = NULL;
term = talloc_asprintf (directory, "%s%u:", term = talloc_asprintf (directory, "%s%u:",
_find_prefix ("directory-direntry"), _find_prefix ("directory-direntry"),
directory->document_id); directory->document_id);
try {
child_directories = _create_filenames_for_terms_with_prefix (directory, child_directories = _create_filenames_for_terms_with_prefix (directory,
directory->notmuch, term); directory->notmuch, term);
} catch (Xapian::Error &error) {
LOG_XAPIAN_EXCEPTION (directory, error);
}
talloc_free (term); talloc_free (term);

View file

@ -2158,6 +2158,8 @@ notmuch_directory_get_child_files (notmuch_directory_t *directory);
* *
* The returned filenames will be the basename-entries only (not * The returned filenames will be the basename-entries only (not
* complete paths). * complete paths).
*
* Returns NULL if it triggers a Xapian exception
*/ */
notmuch_filenames_t * notmuch_filenames_t *
notmuch_directory_get_child_directories (notmuch_directory_t *directory); notmuch_directory_get_child_directories (notmuch_directory_t *directory);

View file

@ -41,7 +41,6 @@ cat <<'EOF' > c_tail
EOF EOF
test_begin_subtest "get child directories for a closed db" test_begin_subtest "get child directories for a closed db"
test_subtest_known_broken
cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR} cat c_head - c_tail <<'EOF' | test_C ${MAIL_DIR}
{ {
notmuch_filenames_t *children; notmuch_filenames_t *children;