summaryrefslogtreecommitdiff
path: root/src/cursor
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 /src/cursor
parenteaf64335f9750e68c34613e1f0a51ceb3b2bcf89 (diff)
downloadmongo-1772c0859b953bce0ab2a2f66d74e4ba00db105e.tar.gz
WT-2998 add error messages to error returns that might be confusing. (#3110)
Diffstat (limited to 'src/cursor')
-rw-r--r--src/cursor/cur_index.c4
-rw-r--r--src/cursor/cur_join.c15
-rw-r--r--src/cursor/cur_json.c84
-rw-r--r--src/cursor/cur_metadata.c5
-rw-r--r--src/cursor/cur_stat.c3
-rw-r--r--src/cursor/cur_table.c2
6 files changed, 55 insertions, 58 deletions
diff --git a/src/cursor/cur_index.c b/src/cursor/cur_index.c
index ea742cac435..eb5e15ae5c3 100644
--- a/src/cursor/cur_index.c
+++ b/src/cursor/cur_index.c
@@ -38,7 +38,9 @@ __curindex_set_value(WT_CURSOR *cursor, ...)
WT_SESSION_IMPL *session;
JOINABLE_CURSOR_API_CALL(cursor, session, set_value, NULL);
- ret = ENOTSUP;
+ WT_ERR_MSG(session, ENOTSUP,
+ "WT_CURSOR.set_value not supported for index cursors");
+
err: cursor->saved_err = ret;
F_CLR(cursor, WT_CURSTD_VALUE_SET);
API_END(session, ret);
diff --git a/src/cursor/cur_join.c b/src/cursor/cur_join.c
index 88eecfddef8..8936c6e3563 100644
--- a/src/cursor/cur_join.c
+++ b/src/cursor/cur_join.c
@@ -38,8 +38,8 @@ __wt_curjoin_joined(WT_CURSOR *cursor)
WT_SESSION_IMPL *session;
session = (WT_SESSION_IMPL *)cursor->session;
- __wt_errx(session, "cursor is being used in a join");
- return (ENOTSUP);
+
+ WT_RET_MSG(session, ENOTSUP, "cursor is being used in a join");
}
/*
@@ -1304,11 +1304,15 @@ __wt_curjoin_open(WT_SESSION_IMPL *session,
WT_STATIC_ASSERT(offsetof(WT_CURSOR_JOIN, iface) == 0);
+ if (owner != NULL)
+ WT_RET_MSG(session, EINVAL,
+ "unable to initialize a join cursor with existing owner");
+
if (!WT_PREFIX_SKIP(uri, "join:"))
- return (EINVAL);
+ return (__wt_unexpected_object_type(session, uri, "join:"));
tablename = uri;
if (!WT_PREFIX_SKIP(tablename, "table:"))
- return (EINVAL);
+ return (__wt_unexpected_object_type(session, uri, "table:"));
columns = strchr(tablename, '(');
if (columns == NULL)
@@ -1336,9 +1340,6 @@ __wt_curjoin_open(WT_SESSION_IMPL *session,
WT_ERR(__wt_strdup(session, columns, &cjoin->projection));
}
- if (owner != NULL)
- WT_ERR(EINVAL);
-
WT_ERR(__wt_cursor_init(cursor, uri, owner, cfg, cursorp));
if (0) {
diff --git a/src/cursor/cur_json.c b/src/cursor/cur_json.c
index bb24e88cba5..093ec3c59ac 100644
--- a/src/cursor/cur_json.c
+++ b/src/cursor/cur_json.c
@@ -492,11 +492,9 @@ __wt_json_token(WT_SESSION *wt_session, const char *src, int *toktype,
uc = (const u_char *)src;
if (__wt_hex2byte(&uc[1], &ignored) ||
- __wt_hex2byte(&uc[3], &ignored)) {
- __wt_errx(session,
+ __wt_hex2byte(&uc[3], &ignored))
+ WT_RET_MSG(session, EINVAL,
"invalid Unicode within JSON string");
- return (-1);
- }
src += 4;
}
backslash = false;
@@ -569,7 +567,10 @@ __wt_json_token(WT_SESSION *wt_session, const char *src, int *toktype,
}
*toklen = (size_t)(src - *tokstart);
*toktype = result;
- return (result < 0 ? EINVAL : 0);
+
+ if (result < 0)
+ WT_RET_MSG(session, EINVAL, "illegal token in JSON");
+ return (0);
}
/*
@@ -606,24 +607,20 @@ __wt_json_tokname(int toktype)
static int
json_string_arg(WT_SESSION_IMPL *session, const char **jstr, WT_ITEM *item)
{
- WT_DECL_RET;
int tok;
const char *tokstart;
- WT_RET(__wt_json_token((WT_SESSION *)session, *jstr, &tok, &tokstart,
- &item->size));
+ WT_RET(__wt_json_token(
+ (WT_SESSION *)session, *jstr, &tok, &tokstart, &item->size));
if (tok == 's') {
*jstr = tokstart + item->size;
/* The tokenizer includes the '"' chars */
item->data = tokstart + 1;
item->size -= 2;
- ret = 0;
- } else {
- __wt_errx(session, "expected JSON <string>, got %s",
- __wt_json_tokname(tok));
- ret = EINVAL;
- }
- return (ret);
+ } else
+ WT_RET_MSG(session, EINVAL,
+ "expected JSON <string>, got %s", __wt_json_tokname(tok));
+ return (0);
}
/*
@@ -648,11 +645,9 @@ json_int_arg(WT_SESSION_IMPL *session, const char **jstr, int64_t *ip)
WT_RET_MSG(session, EINVAL,
"JSON <int> extraneous input");
*jstr = tokstart + toksize;
- } else {
- __wt_errx(session, "expected JSON <int>, got %s",
- __wt_json_tokname(tok));
- return (EINVAL);
- }
+ } else
+ WT_RET_MSG(session, EINVAL,
+ "expected JSON <int>, got %s", __wt_json_tokname(tok));
return (0);
}
@@ -678,22 +673,20 @@ json_uint_arg(WT_SESSION_IMPL *session, const char **jstr, uint64_t *up)
WT_RET_MSG(session, EINVAL,
"JSON <int> extraneous input");
*jstr = tokstart + toksize;
- } else {
- __wt_errx(session, "expected unsigned JSON <int>, got %s",
+ } else
+ WT_RET_MSG(session, EINVAL,
+ "expected unsigned JSON <int>, got %s",
__wt_json_tokname(tok));
- return (EINVAL);
- }
return (0);
}
#define JSON_EXPECT_TOKEN_GET(session, jstr, tokval, start, sz) do { \
int __tok; \
WT_RET(__wt_json_token((WT_SESSION *)session, jstr, &__tok, &start, &sz));\
- if (__tok != tokval) { \
- __wt_errx(session, "expected JSON %s, got %s", \
+ if (__tok != tokval) \
+ WT_RET_MSG(session, EINVAL, \
+ "expected JSON %s, got %s", \
__wt_json_tokname(tokval), __wt_json_tokname(__tok)); \
- return (EINVAL); \
- } \
jstr = start + sz; \
} while (0)
@@ -782,11 +775,10 @@ __json_pack_size(
JSON_EXPECT_TOKEN_GET(session, jstr, 's', tokstart, toksize);
WT_RET(__pack_name_next(&packname, &name));
if (toksize - 2 != name.len ||
- strncmp(tokstart + 1, name.str, toksize - 2) != 0) {
- __wt_errx(session, "JSON expected %s name: \"%.*s\"",
+ strncmp(tokstart + 1, name.str, toksize - 2) != 0)
+ WT_RET_MSG(session, EINVAL,
+ "JSON expected %s name: \"%.*s\"",
iskey ? "key" : "value", (int)name.len, name.str);
- return (EINVAL);
- }
JSON_EXPECT_TOKEN(session, jstr, ':');
WT_PACK_JSON_GET(session, pv, jstr);
total += __pack_size(session, &pv);
@@ -861,9 +853,8 @@ __wt_json_strlen(const char *src, size_t srclen)
/*
* __wt_json_strncpy --
- * Copy bytes of string in JSON format to a destination,
- * up to dstlen bytes. If dstlen is greater than the needed size,
- * the result if zero padded.
+ * Copy bytes of string in JSON format to a destination, up to dstlen
+ * bytes. If dstlen is greater than the needed size, the result if zero padded.
*/
int
__wt_json_strncpy(WT_SESSION *wt_session, char **pdst, size_t dstlen,
@@ -884,18 +875,16 @@ __wt_json_strncpy(WT_SESSION *wt_session, char **pdst, size_t dstlen,
if ((ch = *src++) == '\\')
switch (ch = *src++) {
case 'u':
- if (__wt_hex2byte((const u_char *)src, &hi))
- return (EINVAL);
- src += 2;
- if (__wt_hex2byte((const u_char *)src, &lo))
- return (EINVAL);
- src += 2;
- if (hi != 0) {
- __wt_errx(NULL, "Unicode \"%6.6s\""
- " byte out of range in JSON",
+ if (__wt_hex2byte((const u_char *)src, &hi) ||
+ __wt_hex2byte((const u_char *)src + 2, &lo))
+ WT_RET_MSG(session, EINVAL,
+ "invalid Unicode within JSON string");
+ src += 4;
+ if (hi != 0)
+ WT_RET_MSG(session, EINVAL,
+ "Unicode \"%6.6s\" byte out of "
+ "range in JSON",
src - 6);
- return (EINVAL);
- }
*dst++ = (char)lo;
break;
case 'f':
@@ -920,7 +909,8 @@ __wt_json_strncpy(WT_SESSION *wt_session, char **pdst, size_t dstlen,
*dst++ = ch;
}
if (src != srcend)
- return (ENOMEM);
+ WT_RET_MSG(session,
+ ENOMEM, "JSON string copy destination buffer too small");
*pdst = dst;
while (dst < dstend)
*dst++ = '\0';
diff --git a/src/cursor/cur_metadata.c b/src/cursor/cur_metadata.c
index fd00acdf0ab..10e2fdf28be 100644
--- a/src/cursor/cur_metadata.c
+++ b/src/cursor/cur_metadata.c
@@ -48,7 +48,10 @@ __schema_source_config(WT_SESSION_IMPL *session,
WT_ERR(__wt_buf_fmt(session, buf, "%.*s", (int)cval.len, cval.str));
srch->set_key(srch, buf->data);
if ((ret = srch->search(srch)) == WT_NOTFOUND)
- WT_ERR(EINVAL);
+ WT_ERR_MSG(session, EINVAL,
+ "metadata information for source configuration \"%s\" "
+ "not found",
+ (char *)buf->data);
WT_ERR(ret);
WT_ERR(srch->get_value(srch, &v));
WT_ERR(__wt_strdup(session, v, result));
diff --git a/src/cursor/cur_stat.c b/src/cursor/cur_stat.c
index b36416debe1..5fde64c74ca 100644
--- a/src/cursor/cur_stat.c
+++ b/src/cursor/cur_stat.c
@@ -383,7 +383,8 @@ __curstat_file_init(WT_SESSION_IMPL *session,
if (F_ISSET(cst, WT_STAT_TYPE_SIZE)) {
filename = uri;
if (!WT_PREFIX_SKIP(filename, "file:"))
- return (EINVAL);
+ return (
+ __wt_unexpected_object_type(session, uri, "file:"));
__wt_stat_dsrc_init_single(&cst->u.dsrc_stats);
WT_RET(__wt_block_manager_named_size(session, filename, &size));
cst->u.dsrc_stats.block_size = size;
diff --git a/src/cursor/cur_table.c b/src/cursor/cur_table.c
index 6543d54e90f..502d93639a8 100644
--- a/src/cursor/cur_table.c
+++ b/src/cursor/cur_table.c
@@ -892,7 +892,7 @@ __wt_curtable_open(WT_SESSION_IMPL *session,
tablename = uri;
if (!WT_PREFIX_SKIP(tablename, "table:"))
- return (EINVAL);
+ return (__wt_unexpected_object_type(session, uri, "table:"));
columns = strchr(tablename, '(');
if (columns == NULL)
size = strlen(tablename);