diff --git a/src/plugins_types/instanceid.c b/src/plugins_types/instanceid.c
index ff443e950..804f704bb 100644
--- a/src/plugins_types/instanceid.c
+++ b/src/plugins_types/instanceid.c
@@ -237,7 +237,6 @@ lyplg_type_validate_tree_instanceid(const struct ly_ctx *ctx, const struct lysc_
const struct lyd_node *ctx_node, const struct lyd_node *UNUSED(tree), struct lyd_value *storage,
struct ly_err_item **err)
{
- LY_ERR ret = LY_SUCCESS;
struct lysc_type_instanceid *type_inst = (struct lysc_type_instanceid *)storage->realtype;
const char *value;
char *path;
@@ -253,10 +252,10 @@ lyplg_type_validate_tree_instanceid(const struct ly_ctx *ctx, const struct lysc_
}
/* find the target in data */
- if ((ret = ly_path_eval(storage->target, ctx_node, NULL, NULL))) {
+ if (ly_path_eval(storage->target, ctx_node, NULL, NULL)) {
value = lyd_value_get_canonical(ctx, storage);
path = lyd_path(ctx_node, LYD_PATH_STD, NULL, 0);
- return ly_err_new(err, ret, LYVE_DATA, path, strdup("instance-required"), LY_ERRMSG_NOINST, value);
+ return ly_err_new(err, LY_EVALID, LYVE_DATA, path, strdup("instance-required"), LY_ERRMSG_NOINST, value);
}
return LY_SUCCESS;
diff --git a/tests/utests/data/test_validation.c b/tests/utests/data/test_validation.c
index 999d0685a..f6ce3a5fc 100644
--- a/tests/utests/data/test_validation.c
+++ b/tests/utests/data/test_validation.c
@@ -1301,6 +1301,52 @@ test_multi_error(void **state)
CHECK_LOG_CTX_APPTAG("Duplicate instance of \"l\".", "/ii:cont/l", 0, NULL);
}
+static void
+test_require_instance(void **state)
+{
+ struct lyd_node *tree;
+ const char *schema =
+ "module ri {\n"
+ " namespace urn:tests:ri;\n"
+ " prefix ri;\n"
+ " yang-version 1.1;\n"
+ "\n"
+ " leaf t {\n"
+ " type string;\n"
+ " }\n"
+ " leaf lr {\n"
+ " type leafref {\n"
+ " path \"/ri:t\";\n"
+ " }\n"
+ " }\n"
+ " leaf ii {\n"
+ " type instance-identifier;\n"
+ " }\n"
+ "}";
+ const char *data;
+
+ UTEST_ADD_MODULE(schema, LYS_IN_YANG, NULL, NULL);
+
+ CHECK_PARSE_LYD_PARAM("x", LYD_XML, 0, LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+ CHECK_LOG_CTX_APPTAG("Invalid leafref value \"x\" - no target instance \"/ri:t\" with the same value.", "/ri:lr", 0,
+ "instance-required");
+
+ CHECK_PARSE_LYD_PARAM("/ri:t", LYD_XML, 0,
+ LYD_VALIDATE_PRESENT, LY_EVALID, tree);
+ CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/ri:t\" value - required instance not found.", "/ri:ii", 0,
+ "instance-required");
+
+ /* both errors */
+ data =
+ "x\n"
+ "/ri:t\n";
+ CHECK_PARSE_LYD_PARAM(data, LYD_XML, 0, LYD_VALIDATE_PRESENT | LYD_VALIDATE_MULTI_ERROR, LY_EVALID, tree);
+ CHECK_LOG_CTX_APPTAG("Invalid leafref value \"x\" - no target instance \"/ri:t\" with the same value.", "/ri:lr", 0,
+ "instance-required");
+ CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/ri:t\" value - required instance not found.", "/ri:ii", 0,
+ "instance-required");
+}
+
const char *schema_j =
"module j {\n"
" namespace urn:tests:j;\n"
@@ -1950,6 +1996,7 @@ main(void)
UTEST(test_state),
UTEST(test_must),
UTEST(test_multi_error),
+ UTEST(test_require_instance),
UTEST(test_when_must_cross_ref),
UTEST(test_action),
UTEST(test_rpc),
diff --git a/tests/utests/extensions/test_structure.c b/tests/utests/extensions/test_structure.c
index ada19d8ac..8dc9f1c6a 100644
--- a/tests/utests/extensions/test_structure.c
+++ b/tests/utests/extensions/test_structure.c
@@ -296,7 +296,7 @@ test_parse(void **state)
lyd_free_tree(node->next);
assert_string_equal(LYD_NAME(node), "x");
lyd_free_tree(node);
- assert_int_equal(LY_ENOTFOUND, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
+ assert_int_equal(LY_EVALID, lyd_validate_all(&tree, NULL, LYD_VALIDATE_PRESENT, NULL));
CHECK_LOG_CTX("Invalid instance-identifier \"/a:x/y\" value - required instance not found.",
"/a:struct/x/struct/x/z", 0);
lyd_free_all(tree);
diff --git a/tests/utests/types/instanceid.c b/tests/utests/types/instanceid.c
index 683ad6932..0864f09a0 100644
--- a/tests/utests/types/instanceid.c
+++ b/tests/utests/types/instanceid.c
@@ -158,12 +158,12 @@ test_data_xml(void **state)
/* non-existing instances, instance-identifier is here in JSON format because it is already in internal
* representation without canonical prefixes */
TEST_ERROR_XML2("",
- "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont/m:l2", LY_ENOTFOUND);
+ "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont/m:l2", LY_EVALID);
CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/mod:cont/l2\" value - required instance not found.",
"/defs:l1", 0, "instance-required");
TEST_ERROR_XML2("1",
- "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:llist[.='2']", LY_ENOTFOUND);
+ "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:llist[.='2']", LY_EVALID);
CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/defs:llist[.='2']\" value - required instance not found.",
"/defs:l1", 0, "instance-required");
@@ -171,7 +171,7 @@ test_data_xml(void **state)
"cb"
"a"
"b",
- "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:list2[a:id='a'][a:id2='a']/a:id", LY_ENOTFOUND);
+ "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:list2[a:id='a'][a:id2='a']/a:id", LY_EVALID);
CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/defs:list2[id='a'][id2='a']/id\" value - required instance not found.",
"/defs:l1", 0, "instance-required");
@@ -179,12 +179,12 @@ test_data_xml(void **state)
"cb"
"1"
"2",
- "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:llist[.='3']", LY_ENOTFOUND);
+ "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:llist[.='3']", LY_EVALID);
CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/defs:llist[.='3']\" value - required instance not found.",
"/defs:l1", 0, "instance-required");
TEST_ERROR_XML2("",
- "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:list-keyless[3]", LY_ENOTFOUND);
+ "defs", "xmlns:a=\"urn:tests:defs\"", "l1", "/a:list-keyless[3]", LY_EVALID);
CHECK_LOG_CTX_APPTAG("Invalid instance-identifier \"/defs:list-keyless[3]\" value - required instance not found.",
"/defs:l1", 0, "instance-required");