cli/insert: return EX_TEMPFAIL for some errors

Attempt to distinguish between errors indicating misconfiguration or
programmer error, which we consider "permanent", in the sense that
automatic retries are unlikely to be useful, and those indicating
transient error conditions. We consider XAPIAN_EXCEPTION transient
because it covers the important special case of locking failure.
This commit is contained in:
David Bremner 2016-11-27 23:01:42 -04:00
parent 9259b97fa2
commit d74c534570
4 changed files with 47 additions and 15 deletions

View file

@ -489,6 +489,9 @@ print_status_database (const char *loc,
const notmuch_database_t *database, const notmuch_database_t *database,
notmuch_status_t status); notmuch_status_t status);
int
status_to_exit (notmuch_status_t status);
#include "command-line-arguments.h" #include "command-line-arguments.h"
extern char *notmuch_requested_db_uuid; extern char *notmuch_requested_db_uuid;

View file

@ -538,9 +538,10 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (notmuch_database_open (notmuch_config_get_database_path (config), status = notmuch_database_open (notmuch_config_get_database_path (config),
NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch)) NOTMUCH_DATABASE_MODE_READ_WRITE, &notmuch);
return EXIT_FAILURE; if (status)
return keep ? NOTMUCH_STATUS_SUCCESS : status_to_exit (status);
notmuch_exit_if_unmatched_db_uuid (notmuch); notmuch_exit_if_unmatched_db_uuid (notmuch);
@ -577,5 +578,5 @@ notmuch_insert_command (notmuch_config_t *config, int argc, char *argv[])
notmuch_run_hook (db_path, "post-insert"); notmuch_run_hook (db_path, "post-insert");
} }
return status ? EXIT_FAILURE : EXIT_SUCCESS; return status_to_exit (status);
} }

View file

@ -36,3 +36,19 @@ print_status_database (const char *loc,
} }
return status; return status;
} }
int
status_to_exit (notmuch_status_t status)
{
switch (status) {
case NOTMUCH_STATUS_SUCCESS:
return EXIT_SUCCESS;
case NOTMUCH_STATUS_OUT_OF_MEMORY:
case NOTMUCH_STATUS_XAPIAN_EXCEPTION:
case NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID:
case NOTMUCH_STATUS_FILE_ERROR:
return EX_TEMPFAIL;
default:
return EXIT_FAILURE;
}
}

View file

@ -189,7 +189,6 @@ notmuch config set new.tags $OLDCONFIG
for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \ for code in OUT_OF_MEMORY XAPIAN_EXCEPTION FILE_NOT_EMAIL \
READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
gen_insert_msg
cat <<EOF > index-file-$code.gdb cat <<EOF > index-file-$code.gdb
set breakpoint pending on set breakpoint pending on
set logging file index-file-$code.log set logging file index-file-$code.log
@ -201,17 +200,30 @@ continue
end end
run run
EOF EOF
test_begin_subtest "error exit when add_message returns $code" done
gdb --batch-silent --return-child-result \
-ex "set args insert < $gen_msg_filename" \
-x index-file-$code.gdb notmuch
test_expect_equal $? 1
test_begin_subtest "success exit with --keep when add_message returns $code" gen_insert_msg
gdb --batch-silent --return-child-result \
-ex "set args insert --keep < $gen_msg_filename" \ for code in FILE_NOT_EMAIL READ_ONLY_DATABASE UPGRADE_REQUIRED PATH_ERROR; do
-x index-file-$code.gdb notmuch test_expect_code 1 "EXIT_FAILURE when add_message returns $code" \
test_expect_equal $? 0 "gdb --batch-silent --return-child-result \
-ex 'set args insert < $gen_msg_filename' \
-x index-file-$code.gdb notmuch"
test_expect_code 0 "success exit with --keep when add_message returns $code" \
"gdb --batch-silent --return-child-result \
-ex 'set args insert --keep < $gen_msg_filename' \
-x index-file-$code.gdb notmuch"
done
for code in OUT_OF_MEMORY XAPIAN_EXCEPTION ; do
test_expect_code 75 "EX_TEMPFAIL when add_message returns $code" \
"gdb --batch-silent --return-child-result \
-ex 'set args insert < $gen_msg_filename' \
-x index-file-$code.gdb notmuch"
test_expect_code 0 "success exit with --keep when add_message returns $code" \
"gdb --batch-silent --return-child-result \
-ex 'set args insert --keep < $gen_msg_filename' \
-x index-file-$code.gdb notmuch"
done done
test_done test_done