plugin types BUGFIX no context logging in plugins types
diff --git a/src/plugins_types.c b/src/plugins_types.c
index 7f62be8..d23670c 100644
--- a/src/plugins_types.c
+++ b/src/plugins_types.c
@@ -811,6 +811,8 @@
     LY_ERR ret = LY_SUCCESS;
     struct lyxp_expr *exp = NULL;
     uint32_t prefix_opt = 0;
+    struct ly_err_item *e;
+    const char *err_fmt;
 
     LY_CHECK_ARG_RET(ctx, ctx, value, ctx_node, path, err, LY_EINVAL);
 
@@ -831,31 +833,43 @@
         break;
     }
 
+    /* remember the current last error */
+    e = ly_err_last(ctx);
+
     /* parse the value */
     ret = ly_path_parse(ctx, ctx_node, value, value_len, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
     if (ret) {
-        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL,
-                "Invalid instance-identifier \"%.*s\" value - syntax error.", (int)value_len, value);
+        err_fmt = "Invalid instance-identifier \"%.*s\" value - syntax error%s%s";
         goto cleanup;
     }
 
     if (options & LYPLG_TYPE_STORE_IMPLEMENT) {
         /* implement all prefixes */
-        LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
+        ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL);
+        if (ret) {
+            err_fmt = "Failed to implement a module referenced by instance-identifier \"%.*s\"%s%s";
+            goto cleanup;
+        }
     }
 
     /* resolve it on schema tree */
     ret = ly_path_compile(ctx, NULL, ctx_node, NULL, exp, (ctx_node->flags & LYS_IS_OUTPUT) ?
             LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_SINGLE, 1, format, prefix_data, path);
     if (ret) {
-        ret = ly_err_new(err, ret, LYVE_DATA, NULL, NULL,
-                "Invalid instance-identifier \"%.*s\" value - semantic error.", (int)value_len, value);
+        err_fmt = "Invalid instance-identifier \"%.*s\" value - semantic error%s%s";
         goto cleanup;
     }
 
 cleanup:
     lyxp_expr_free(ctx, exp);
     if (ret) {
+        /* generate error, spend the context error, if any */
+        e = e ? e->next : ly_err_last(ctx);
+        ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, err_fmt, (int)value_len, value, e ? ": " : ".", e ? e->msg : "");
+        if (e) {
+            ly_err_clean((struct ly_ctx *)ctx, e);
+        }
+
         ly_path_free(ctx, *path);
         *path = NULL;
     }
diff --git a/tests/utests/schema/test_tree_schema_compile.c b/tests/utests/schema/test_tree_schema_compile.c
index 47375b1..85da486 100644
--- a/tests/utests/schema/test_tree_schema_compile.c
+++ b/tests/utests/schema/test_tree_schema_compile.c
@@ -315,8 +315,7 @@
     assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
             "leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG, NULL));
     CHECK_LOG_CTX("Invalid default - value does not fit the type "
-            "(Invalid instance-identifier \"/ee:g\" value - semantic error.).", "Schema location \"/ee:ref\".");
-    CHECK_LOG_CTX("Not found node \"g\" in path.", "Schema location \"/ee:ref\".");
+            "(Invalid instance-identifier \"/ee:g\" value - semantic error: Not found node \"g\" in path.).", "Schema location \"/ee:ref\".");
 }
 
 static void
diff --git a/tests/utests/types/instanceid.c b/tests/utests/types/instanceid.c
index 4174e4d..3126f61 100644
--- a/tests/utests/types/instanceid.c
+++ b/tests/utests/types/instanceid.c
@@ -136,30 +136,23 @@
     TEST_ERROR_XML2("<list xmlns=\"urn:tests:defs\"><id>a</id></list>"
             "<list xmlns=\"urn:tests:defs\"><id>b</id><value>x</value></list>",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/xdf:list[2]/xdf:value", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[2]/xdf:value\" value - semantic error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Positional predicate defined for configuration list \"list\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[2]/xdf:value\" value - semantic error: "
+            "Positional predicate defined for configuration list \"list\" in path.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/t:cont/t:1l", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:1l\" value - syntax error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Invalid character 't'[9] of expression '/t:cont/t:1l'.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:1l\" value - syntax error: Invalid character 't'[9] of expression '/t:cont/t:1l'.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/t:cont:t:1l", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont:t:1l\" value - syntax error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Invalid character ':'[8] of expression '/t:cont:t:1l'.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont:t:1l\" value - syntax error: Invalid character ':'[8] of expression '/t:cont:t:1l'.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/xdf:cont/xdf:invalid/xdf:path", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:cont/xdf:invalid/xdf:path\" value - semantic error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Not found node \"invalid\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:cont/xdf:invalid/xdf:path\" value - semantic error: Not found node \"invalid\" in path.",
             "Schema location \"/defs:l1\", line number 1.");
 
     /* non-existing instances, instance-identifier is here in JSON format because it is already in internal
@@ -198,100 +191,72 @@
     /* more errors */
     TEST_ERROR_XML2("<llist xmlns=\"urn:tests:defs\">x</llist>",
             "defs", "xmlns:t=\"urn:tests:defs\"", "t:l1", "/t:llist[1", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1\" value - syntax error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Unexpected XPath expression end.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1\" value - syntax error: Unexpected XPath expression end.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"/>",
             "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont[1]", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont[1]\" value - semantic error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Positional predicate defined for container \"cont\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont[1]\" value - semantic error: Positional predicate defined for container \"cont\" in path.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"/>",
             "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "[1]", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Unexpected XPath token \"[\" (\"[1]\"), expected \"Operator(Path)\".",
+    CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error: Unexpected XPath token \"[\" (\"[1]\"), expected \"Operator(Path)\".",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"><l2/></cont>",
             "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont/m:l2[l2='1']", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[l2='1']\" value - syntax error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Prefix missing for \"l2\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[l2='1']\" value - syntax error: Prefix missing for \"l2\" in path.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"><l2/></cont>",
             "defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont/m:l2[m:l2='1']", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[m:l2='1']\" value - semantic error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("List predicate defined for leaf \"l2\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[m:l2='1']\" value - semantic error: List predicate defined for leaf \"l2\" in path.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("<llist xmlns=\"urn:tests:defs\">1</llist><llist xmlns=\"urn:tests:defs\">2</llist>",
             "defs", "xmlns:t=\"urn:tests:defs\"", "t:l1", "/t:llist[4]", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[4]\" value - semantic error.",
-            "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Positional predicate defined for configuration leaf-list \"llist\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[4]\" value - semantic error: Positional predicate defined for configuration leaf-list \"llist\" in path.",
             "Schema location \"/defs:l1\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/t:llist[6]", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[6]\" value - semantic error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("No module connected with the prefix \"t\" found (prefix format XML prefixes).",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[6]\" value - semantic error: No module connected with the prefix \"t\" found (prefix format XML prefixes).",
             "Schema location \"/defs:l2\", line number 1.");
 
     TEST_ERROR_XML2("<list xmlns=\"urn:tests:defs\"><id>1</id><value>x</value></list>",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list[xdf:value='x']", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:value='x']\" value - semantic error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("Key expected instead of leaf \"value\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:value='x']\" value - semantic error: Key expected instead of leaf \"value\" in path.",
             "Schema location \"/defs:l2\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list[.='x']", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[.='x']\" value - semantic error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("Leaf-list predicate defined for list \"list\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[.='x']\" value - semantic error: Leaf-list predicate defined for list \"list\" in path.",
             "Schema location \"/defs:l2\", line number 1.");
 
     TEST_ERROR_XML2("<llist xmlns=\"urn:tests:defs\">1</llist>",
             "defs", "xmlns:t=\"urn:tests:defs\"", "t:l1", "/t:llist[.='x']", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='x']\" value - semantic error.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='x']\" value - semantic error: Invalid type uint32 value \"x\".",
             "Schema location \"/defs:l1\", line number 1.");
-    CHECK_LOG_CTX("Invalid type uint32 value \"x\".",
-            "Schema location \"/defs:llist\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/t:llist[1][2]", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1][2]\" value - syntax error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("Unparsed characters \"[2]\" left at the end of path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1][2]\" value - syntax error: Unparsed characters \"[2]\" left at the end of path.",
             "Schema location \"/defs:l2\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/t:llist[.='a'][.='b']", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='a'][.='b']\" value - syntax error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("Unparsed characters \"[.='b']\" left at the end of path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='a'][.='b']\" value - syntax error: Unparsed characters \"[.='b']\" left at the end of path.",
             "Schema location \"/defs:l2\", line number 1.");
 
     TEST_ERROR_XML2("<list xmlns=\"urn:tests:defs\"><id>1</id><value>x</value></list>",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list[xdf:id='1'][xdf:id='2']/xdf:value", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:id='1'][xdf:id='2']/xdf:value\" value - syntax error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("Duplicate predicate key \"id\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:id='1'][xdf:id='2']/xdf:value\" value - syntax error: Duplicate predicate key \"id\" in path.",
             "Schema location \"/defs:l2\", line number 1.");
 
     TEST_ERROR_XML2("",
             "defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list2[xdf:id='1']/xdf:value", LY_EVALID);
-    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list2[xdf:id='1']/xdf:value\" value - semantic error.",
-            "Schema location \"/defs:l2\", line number 1.");
-    CHECK_LOG_CTX("Predicate missing for a key of list \"list2\" in path.",
+    CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list2[xdf:id='1']/xdf:value\" value - semantic error: Predicate missing for a key of list \"list2\" in path.",
             "Schema location \"/defs:l2\", line number 1.");
 }