common REFACTOR minor error message improvements
diff --git a/src/common.h b/src/common.h
index d3623e1..438c7f8 100644
--- a/src/common.h
+++ b/src/common.h
@@ -262,23 +262,29 @@
#define LY_VCODE_DEV_NOT_PRESENT LYVE_REFERENCE, "Invalid deviation %s \"%s\" property \"%s\" which is not present."
-/* RFC 7950 section 15 errors (errmsg is used in type plugin validation callbacks) */
-#define LY_VCODE_NOUNIQ LYVE_DATA, "Unique data leaf(s) \"%s\" not satisfied in \"%s\" and \"%s\"."
-#define LY_VCODE_NOMAX LYVE_DATA, "Too many \"%s\" instances."
-#define LY_VCODE_NOMIN LYVE_DATA, "Too few \"%s\" instances."
-#define LY_VCODE_NOMUST LYVE_DATA, "Must condition \"%s\" not satisfied."
-#define LY_ERRMSG_NOLREF_VAL /* LYVE_DATA */ "Invalid leafref value \"%s\" - no target instance \"%s\" with the same value."
-#define LY_ERRMSG_NOLREF_INST /* LYVE_DATA */ "Invalid leafref value \"%s\" - no existing target instance \"%s\"."
-#define LY_ERRMSG_NOINST /* LYVE_DATA */ "Invalid instance-identifier \"%s\" value - required instance not found."
-#define LY_VCODE_NOMAND_CHOIC LYVE_DATA, "Mandatory choice \"%s\" data do not exist."
-
#define LY_VCODE_NOWHEN LYVE_DATA, "When condition \"%s\" not satisfied."
#define LY_VCODE_NOMAND LYVE_DATA, "Mandatory node \"%s\" instance does not exist."
#define LY_VCODE_DUP LYVE_DATA, "Duplicate instance of \"%s\"."
#define LY_VCODE_DUPCASE LYVE_DATA, "Data for both cases \"%s\" and \"%s\" exist."
-#define LY_VCODE_INNODE LYVE_DATA, "Invalid %s data node \"%s\" found."
+#define LY_VCODE_UNEXPNODE LYVE_DATA, "Unexpected data %s node \"%s\" found."
#define LY_VCODE_NOKEY LYVE_DATA, "List instance is missing its key \"%s\"."
+#define LY_ERRMSG_NOPATTERN /* LYVE_DATA */ "Unsatisfied pattern - \"%.*s\" does not conform to %s\"%s\"."
+#define LY_ERRMSG_NOLENGTH /* LYVE_DATA */ "Unsatisfied length - string length \"%s\" is not allowed."
+#define LY_ERRMSG_NORANGE /* LYVE_DATA */ "Unsatisfied range - value \"%s\" is out of the allowed range."
+
+/* RFC 7950 section 15 errors */
+#define LY_VCODE_NOUNIQ LYVE_DATA, "Unique data leaf(s) \"%s\" not satisfied in \"%s\" and \"%s\"."
+#define LY_VCODE_NOMAX LYVE_DATA, "Too many \"%s\" instances."
+#define LY_VCODE_NOMIN LYVE_DATA, "Too few \"%s\" instances."
+#define LY_VCODE_NOMUST LYVE_DATA, "Must condition \"%s\" not satisfied."
+#define LY_VCODE_NOMAND_CHOIC LYVE_DATA, "Mandatory choice \"%s\" data do not exist."
+
+/* RFC 7950 section 15 error messages used in type plugin validation callbacks */
+#define LY_ERRMSG_NOLREF_VAL /* LYVE_DATA */ "Invalid leafref value \"%s\" - no target instance \"%s\" with the same value."
+#define LY_ERRMSG_NOLREF_INST /* LYVE_DATA */ "Invalid leafref value \"%s\" - no existing target instance \"%s\"."
+#define LY_ERRMSG_NOINST /* LYVE_DATA */ "Invalid instance-identifier \"%s\" value - required instance not found."
+
/******************************************************************************
* Context
*****************************************************************************/
diff --git a/src/in.c b/src/in.c
index f4c8fd6..58666d9 100644
--- a/src/in.c
+++ b/src/in.c
@@ -434,7 +434,7 @@
LOG_LOCSET(snode, NULL, NULL, NULL);
if ((lydctx->parse_opts & LYD_PARSE_NO_STATE) && (snode->flags & LYS_CONFIG_R)) {
- LOGVAL(lydctx->data_ctx->ctx, LY_VCODE_INNODE, "state", snode->name);
+ LOGVAL(lydctx->data_ctx->ctx, LY_VCODE_UNEXPNODE, "state", snode->name);
rc = LY_EVALID;
goto cleanup;
}
diff --git a/src/plugins_types.c b/src/plugins_types.c
index f78e4c4..30ef885 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -513,16 +513,15 @@
*err = ly_err_new(LY_LLERR, LY_ESYS, 0, strdup((const char *)pcre2_errmsg), NULL, NULL);
return LY_ESYS;
- } else if (((rc == PCRE2_ERROR_NOMATCH) && (patterns[u]->inverted == 0)) ||
- ((rc != PCRE2_ERROR_NOMATCH) && (patterns[u]->inverted == 1))) {
+ } else if (((rc == PCRE2_ERROR_NOMATCH) && !patterns[u]->inverted) ||
+ ((rc != PCRE2_ERROR_NOMATCH) && patterns[u]->inverted)) {
LY_ERR ret = 0;
- const char *inverted = patterns[u]->inverted == 0 ? " " : " inverted ";
- if (asprintf(&errmsg, "String \"%.*s\" does not conform to the%spattern \"%s\".",
- (int)str_len, str, inverted, patterns[u]->expr) == -1) {
+ const char *inverted = patterns[u]->inverted ? "inverted " : "";
+ if (asprintf(&errmsg, LY_ERRMSG_NOPATTERN, (int)str_len, str, inverted, patterns[u]->expr) == -1) {
*err = ly_err_new(LY_LLERR, LY_EMEM, 0, LY_EMEM_MSG, NULL, NULL);
ret = LY_EMEM;
} else {
- *err = ly_err_new(LY_LLERR, LY_ESYS, 0, errmsg, NULL, NULL);
+ *err = ly_err_new(LY_LLERR, LY_EVALID, 0, errmsg, NULL, NULL);
ret = LY_EVALID;
}
return ret;
@@ -538,6 +537,9 @@
LY_ARRAY_COUNT_TYPE u;
char *errmsg = NULL;
int rc = 0;
+ ly_bool is_length; /* length or range */
+
+ is_length = (basetype == LY_TYPE_BINARY || basetype == LY_TYPE_STRING) ? 1 : 0;
LY_ARRAY_FOR(range->parts, u) {
if (basetype < LY_TYPE_DEC64) {
@@ -546,9 +548,7 @@
if (range->emsg) {
errmsg = strdup(range->emsg);
} else {
- rc = asprintf(&errmsg, "%s \"%s\" does not satisfy the %s constraint.",
- (basetype == LY_TYPE_BINARY || basetype == LY_TYPE_STRING) ? "Length" : "Value", strval,
- (basetype == LY_TYPE_BINARY || basetype == LY_TYPE_STRING) ? "length" : "range");
+ rc = asprintf(&errmsg, is_length ? LY_ERRMSG_NOLENGTH : LY_ERRMSG_NORANGE, strval);
}
goto error;
} else if ((uint64_t)value <= range->parts[u].max_u64) {
@@ -559,9 +559,7 @@
if (range->emsg) {
errmsg = strdup(range->emsg);
} else {
- rc = asprintf(&errmsg, "%s \"%s\" does not satisfy the %s constraint.",
- (basetype == LY_TYPE_BINARY || basetype == LY_TYPE_STRING) ? "Length" : "Value", strval,
- (basetype == LY_TYPE_BINARY || basetype == LY_TYPE_STRING) ? "length" : "range");
+ rc = asprintf(&errmsg, is_length ? LY_ERRMSG_NOLENGTH : LY_ERRMSG_NORANGE, strval);
}
goto error;
}
@@ -571,7 +569,7 @@
if (range->emsg) {
errmsg = strdup(range->emsg);
} else {
- rc = asprintf(&errmsg, "Value \"%s\" does not satisfy the range constraint.", strval);
+ rc = asprintf(&errmsg, LY_ERRMSG_NORANGE, strval);
}
goto error;
} else if (value <= range->parts[u].max_64) {
@@ -582,7 +580,7 @@
if (range->emsg) {
errmsg = strdup(range->emsg);
} else {
- rc = asprintf(&errmsg, "Value \"%s\" does not satisfy the range constraint.", strval);
+ rc = asprintf(&errmsg, LY_ERRMSG_NORANGE, strval);
}
goto error;
}
diff --git a/src/validation.c b/src/validation.c
index 4bd196a..c970ffa 100644
--- a/src/validation.c
+++ b/src/validation.c
@@ -1254,13 +1254,13 @@
/* no state/input/output data */
if ((val_opts & LYD_VALIDATE_NO_STATE) && (node->schema->flags & LYS_CONFIG_R)) {
innode = "state";
- goto invalid_node;
+ goto unexpected_node;
} else if ((int_opts & (LYD_INTOPT_RPC | LYD_INTOPT_ACTION)) && (node->schema->flags & LYS_IS_OUTPUT)) {
innode = "output";
- goto invalid_node;
+ goto unexpected_node;
} else if ((int_opts & LYD_INTOPT_REPLY) && (node->schema->flags & LYS_IS_INPUT)) {
innode = "input";
- goto invalid_node;
+ goto unexpected_node;
}
/* obsolete data */
@@ -1296,8 +1296,8 @@
return LY_SUCCESS;
-invalid_node:
- LOGVAL(LYD_CTX(node), LY_VCODE_INNODE, innode, node->schema->name);
+unexpected_node:
+ LOGVAL(LYD_CTX(node), LY_VCODE_UNEXPNODE, innode, node->schema->name);
LOG_LOCBACK(1, 1, 0, 0);
return LY_EVALID;
}