summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorKeith Bostic <keith.bostic@mongodb.com>2016-11-01 00:32:48 -0400
committerMichael Cahill <michael.cahill@mongodb.com>2016-11-01 15:32:48 +1100
commit1772c0859b953bce0ab2a2f66d74e4ba00db105e (patch)
tree0537790c8cd8d5c75bb3d18ff4cfe0e9debf221d /ext
parenteaf64335f9750e68c34613e1f0a51ceb3b2bcf89 (diff)
downloadmongo-1772c0859b953bce0ab2a2f66d74e4ba00db105e.tar.gz
WT-2998 add error messages to error returns that might be confusing. (#3110)
Diffstat (limited to 'ext')
-rw-r--r--ext/compressors/zlib/zlib_compress.c18
-rw-r--r--ext/encryptors/nop/nop_encrypt.c25
-rw-r--r--ext/encryptors/rotn/rotn_encrypt.c13
-rw-r--r--ext/extractors/csv/csv_extractor.c51
4 files changed, 81 insertions, 26 deletions
diff --git a/ext/compressors/zlib/zlib_compress.c b/ext/compressors/zlib/zlib_compress.c
index 9ee8fe3bd8b..0539569015f 100644
--- a/ext/compressors/zlib/zlib_compress.c
+++ b/ext/compressors/zlib/zlib_compress.c
@@ -392,19 +392,27 @@ err: if ((tret = deflateEnd(zs)) != Z_OK && tret != Z_DATA_ERROR)
#if 0
/* Decompress the result and confirm it matches the original source. */
if (ret == 0 && last_slot > 0) {
+ WT_EXTENSION_API *wt_api;
void *decomp;
size_t result_len;
+ wt_api = ((ZLIB_COMPRESSOR *)compressor)->wt_api;
+
if ((decomp = zalloc(
- &opaque, 1, (uint32_t)best_zs->total_in + 100)) == NULL)
+ &opaque, 1, (uint32_t)best_zs->total_in + 100)) == NULL) {
+ (void)wt_api->err_printf(wt_api, session,
+ "zlib_compress_raw: zalloc failure");
return (ENOMEM);
+ }
if ((ret = zlib_decompress(
compressor, session, dst, (size_t)best_zs->total_out,
decomp, (size_t)best_zs->total_in + 100, &result_len)) == 0)
- if (memcmp(src, decomp, result_len) != 0)
- ret = zlib_error(compressor, session,
- "deflate compare with original source",
- Z_DATA_ERROR);
+ if (memcmp(src, decomp, result_len) != 0) {
+ (void)wt_api->err_printf(wt_api, session,
+ "zlib_compress_raw: "
+ "deflate compare with original source");
+ return (WT_ERROR);
+ }
zfree(&opaque, decomp);
}
#endif
diff --git a/ext/encryptors/nop/nop_encrypt.c b/ext/encryptors/nop/nop_encrypt.c
index eac7d8f4632..eb311f09909 100644
--- a/ext/encryptors/nop/nop_encrypt.c
+++ b/ext/encryptors/nop/nop_encrypt.c
@@ -38,13 +38,29 @@
typedef struct {
WT_ENCRYPTOR encryptor; /* Must come first */
- WT_EXTENSION_API *wt_api; /* Extension API */
+ WT_EXTENSION_API *wtext; /* Extension API */
- unsigned long nop_calls; /* Count of calls */
+ unsigned long nop_calls; /* Count of calls */
} NOP_ENCRYPTOR;
/*! [WT_ENCRYPTOR initialization structure] */
+/*
+ * nop_error --
+ * Display an error from this module in a standard way.
+ */
+static int
+nop_error(
+ NOP_ENCRYPTOR *encryptor, WT_SESSION *session, int err, const char *msg)
+{
+ WT_EXTENSION_API *wtext;
+
+ wtext = encryptor->wtext;
+ (void)wtext->err_printf(wtext, session,
+ "nop encryption: %s: %s", msg, wtext->strerror(wtext, NULL, err));
+ return (err);
+}
+
/*! [WT_ENCRYPTOR encrypt] */
/*
* nop_encrypt --
@@ -63,7 +79,8 @@ nop_encrypt(WT_ENCRYPTOR *encryptor, WT_SESSION *session,
++nop_encryptor->nop_calls; /* Call count */
if (dst_len < src_len)
- return (ENOMEM);
+ return (nop_error(nop_encryptor, session,
+ ENOMEM, "encrypt buffer not big enough"));
memcpy(dst, src, src_len);
*result_lenp = src_len;
@@ -169,7 +186,7 @@ wiredtiger_extension_init(WT_CONNECTION *connection, WT_CONFIG_ARG *config)
nop_encryptor->encryptor.sizing = nop_sizing;
nop_encryptor->encryptor.terminate = nop_terminate;
- nop_encryptor->wt_api = connection->get_extension_api(connection);
+ nop_encryptor->wtext = connection->get_extension_api(connection);
/* Load the encryptor */
return (connection->add_encryptor(
diff --git a/ext/encryptors/rotn/rotn_encrypt.c b/ext/encryptors/rotn/rotn_encrypt.c
index 4d614e2e409..23a7ad79a7d 100644
--- a/ext/encryptors/rotn/rotn_encrypt.c
+++ b/ext/encryptors/rotn/rotn_encrypt.c
@@ -89,8 +89,8 @@ typedef struct {
* Display an error from this module in a standard way.
*/
static int
-rotn_error(ROTN_ENCRYPTOR *encryptor, WT_SESSION *session, int err,
- const char *msg)
+rotn_error(
+ ROTN_ENCRYPTOR *encryptor, WT_SESSION *session, int err, const char *msg)
{
WT_EXTENSION_API *wtext;
@@ -189,7 +189,8 @@ rotn_encrypt(WT_ENCRYPTOR *encryptor, WT_SESSION *session,
(void)session; /* Unused */
if (dst_len < src_len + CHKSUM_LEN + IV_LEN)
- return (ENOMEM);
+ return (rotn_error(rotn_encryptor, session,
+ ENOMEM, "encrypt buffer not big enough"));
/*
* !!! Most implementations would verify any needed
@@ -333,7 +334,8 @@ rotn_customize(WT_ENCRYPTOR *encryptor, WT_SESSION *session,
* In this demonstration, we expect keyid to be a number.
*/
if ((keyid_val = atoi(keyid.str)) < 0) {
- ret = EINVAL;
+ ret = rotn_error(rotn_encryptor,
+ NULL, EINVAL, "rotn_customize: invalid keyid");
goto err;
}
if ((rotn_encryptor->keyid = malloc(keyid.len + 1)) == NULL) {
@@ -364,7 +366,8 @@ rotn_customize(WT_ENCRYPTOR *encryptor, WT_SESSION *session,
else if ('A' <= secret.str[i] && secret.str[i] <= 'Z')
base = 'A';
else {
- ret = EINVAL;
+ ret = rotn_error(rotn_encryptor, NULL,
+ EINVAL, "rotn_customize: invalid key");
goto err;
}
base -= (u_char)keyid_val;
diff --git a/ext/extractors/csv/csv_extractor.c b/ext/extractors/csv/csv_extractor.c
index 698a9d6fa96..40e03f7ec1a 100644
--- a/ext/extractors/csv/csv_extractor.c
+++ b/ext/extractors/csv/csv_extractor.c
@@ -54,6 +54,22 @@ typedef struct {
} CSV_EXTRACTOR;
/*
+ * csv_error --
+ * Display an error from this module in a standard way.
+ */
+static int
+csv_error(const CSV_EXTRACTOR *csv_extractor,
+ WT_SESSION *session, int err, const char *msg)
+{
+ WT_EXTENSION_API *wt_api;
+
+ wt_api = csv_extractor->wt_api;
+ (void)wt_api->err_printf(wt_api, session,
+ "csv extraction: %s: %s", msg, wt_api->strerror(wt_api, NULL, err));
+ return (err);
+}
+
+/*
* csv_extract --
* WiredTiger CSV extraction.
*/
@@ -61,11 +77,11 @@ static int
csv_extract(WT_EXTRACTOR *extractor, WT_SESSION *session,
const WT_ITEM *key, const WT_ITEM *value, WT_CURSOR *result_cursor)
{
- char *copy, *p, *pend, *valstr;
const CSV_EXTRACTOR *csv_extractor;
- int i, ret, val;
- size_t len;
WT_EXTENSION_API *wtapi;
+ size_t len;
+ int i, ret, val;
+ char *copy, *p, *pend, *valstr;
(void)key; /* Unused parameters */
@@ -98,8 +114,10 @@ csv_extract(WT_EXTRACTOR *extractor, WT_SESSION *session,
copy[len] = '\0';
if (csv_extractor->format_isnum) {
if ((val = atoi(copy)) < 0) {
+ ret = csv_error(csv_extractor,
+ session, EINVAL, "invalid key value");
free(copy);
- return (EINVAL);
+ return (ret);
}
result_cursor->set_key(result_cursor, val);
} else
@@ -125,29 +143,38 @@ csv_customize(WT_EXTRACTOR *extractor, WT_SESSION *session,
CSV_EXTRACTOR *csv_extractor;
WT_CONFIG_ITEM field, format;
WT_CONFIG_PARSER *parser;
- WT_EXTENSION_API *wtapi;
- int ret;
+ WT_EXTENSION_API *wt_api;
long field_num;
+ int ret;
(void)session; /* Unused parameters */
(void)uri; /* Unused parameters */
orig = (const CSV_EXTRACTOR *)extractor;
- wtapi = orig->wt_api;
- if ((ret = wtapi->config_parser_open(wtapi, session, appcfg->str,
+ wt_api = orig->wt_api;
+ if ((ret = wt_api->config_parser_open(wt_api, session, appcfg->str,
appcfg->len, &parser)) != 0)
return (ret);
if ((ret = parser->get(parser, "field", &field)) != 0 ||
(ret = parser->get(parser, "format", &format)) != 0) {
- if (ret == WT_NOTFOUND)
- return (EINVAL);
+ if (ret == WT_NOTFOUND) {
+ (void)wt_api->err_printf(
+ wt_api, session, "field or format not found");
+ return (WT_NOTFOUND);
+ }
return (ret);
}
field_num = strtol(field.str, NULL, 10);
- if (field_num < 0 || field_num > INT_MAX)
+ if (field_num < 0 || field_num > INT_MAX) {
+ (void)wt_api->err_printf(
+ wt_api, session, "field: invalid format");
return (EINVAL);
- if (format.len != 1 || (format.str[0] != 'S' && format.str[0] != 'i'))
+ }
+ if (format.len != 1 || (format.str[0] != 'S' && format.str[0] != 'i')) {
+ (void)wt_api->err_printf(
+ wt_api, session, "format: invalid format");
return (EINVAL);
+ }
if ((csv_extractor = calloc(1, sizeof(CSV_EXTRACTOR))) == NULL)
return (errno);