Skip to content

Commit bfc9ce6

Browse files
committed
plugin types BUGFIX no context logging in plugins types
1 parent 3a7d5f7 commit bfc9ce6

File tree

3 files changed

+39
-61
lines changed

3 files changed

+39
-61
lines changed

src/plugins_types.c

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -811,6 +811,8 @@ lyplg_type_lypath_new(const struct ly_ctx *ctx, const char *value, size_t value_
811811
LY_ERR ret = LY_SUCCESS;
812812
struct lyxp_expr *exp = NULL;
813813
uint32_t prefix_opt = 0;
814+
struct ly_err_item *e;
815+
const char *err_fmt;
814816

815817
LY_CHECK_ARG_RET(ctx, ctx, value, ctx_node, path, err, LY_EINVAL);
816818

@@ -831,31 +833,43 @@ lyplg_type_lypath_new(const struct ly_ctx *ctx, const char *value, size_t value_
831833
break;
832834
}
833835

836+
/* remember the current last error */
837+
e = ly_err_last(ctx);
838+
834839
/* parse the value */
835840
ret = ly_path_parse(ctx, ctx_node, value, value_len, 0, LY_PATH_BEGIN_ABSOLUTE, prefix_opt, LY_PATH_PRED_SIMPLE, &exp);
836841
if (ret) {
837-
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL,
838-
"Invalid instance-identifier \"%.*s\" value - syntax error.", (int)value_len, value);
842+
err_fmt = "Invalid instance-identifier \"%.*s\" value - syntax error%s%s";
839843
goto cleanup;
840844
}
841845

842846
if (options & LYPLG_TYPE_STORE_IMPLEMENT) {
843847
/* implement all prefixes */
844-
LY_CHECK_GOTO(ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL), cleanup);
848+
ret = lys_compile_expr_implement(ctx, exp, format, prefix_data, 1, unres, NULL);
849+
if (ret) {
850+
err_fmt = "Failed to implement a module referenced by instance-identifier \"%.*s\"%s%s";
851+
goto cleanup;
852+
}
845853
}
846854

847855
/* resolve it on schema tree */
848856
ret = ly_path_compile(ctx, NULL, ctx_node, NULL, exp, (ctx_node->flags & LYS_IS_OUTPUT) ?
849857
LY_PATH_OPER_OUTPUT : LY_PATH_OPER_INPUT, LY_PATH_TARGET_SINGLE, 1, format, prefix_data, path);
850858
if (ret) {
851-
ret = ly_err_new(err, ret, LYVE_DATA, NULL, NULL,
852-
"Invalid instance-identifier \"%.*s\" value - semantic error.", (int)value_len, value);
859+
err_fmt = "Invalid instance-identifier \"%.*s\" value - semantic error%s%s";
853860
goto cleanup;
854861
}
855862

856863
cleanup:
857864
lyxp_expr_free(ctx, exp);
858865
if (ret) {
866+
/* generate error, spend the context error, if any */
867+
e = e ? e->next : ly_err_last(ctx);
868+
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, err_fmt, (int)value_len, value, e ? ": " : ".", e ? e->msg : "");
869+
if (e) {
870+
ly_err_clean((struct ly_ctx *)ctx, e);
871+
}
872+
859873
ly_path_free(ctx, *path);
860874
*path = NULL;
861875
}

tests/utests/schema/test_tree_schema_compile.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ test_node_leaflist(void **state)
315315
assert_int_equal(LY_EVALID, lys_parse_mem(UTEST_LYCTX, "module ee {yang-version 1.1; namespace urn:ee;prefix ee;"
316316
"leaf ref {type instance-identifier {require-instance true;} default \"/ee:g\";}}", LYS_IN_YANG, NULL));
317317
CHECK_LOG_CTX("Invalid default - value does not fit the type "
318-
"(Invalid instance-identifier \"/ee:g\" value - semantic error.).", "Schema location \"/ee:ref\".");
319-
CHECK_LOG_CTX("Not found node \"g\" in path.", "Schema location \"/ee:ref\".");
318+
"(Invalid instance-identifier \"/ee:g\" value - semantic error: Not found node \"g\" in path.).", "Schema location \"/ee:ref\".");
320319
}
321320

322321
static void

tests/utests/types/instanceid.c

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -136,30 +136,23 @@ test_data_xml(void **state)
136136
TEST_ERROR_XML2("<list xmlns=\"urn:tests:defs\"><id>a</id></list>"
137137
"<list xmlns=\"urn:tests:defs\"><id>b</id><value>x</value></list>",
138138
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/xdf:list[2]/xdf:value", LY_EVALID);
139-
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[2]/xdf:value\" value - semantic error.",
140-
"Schema location \"/defs:l1\", line number 1.");
141-
CHECK_LOG_CTX("Positional predicate defined for configuration list \"list\" in path.",
139+
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[2]/xdf:value\" value - semantic error: "
140+
"Positional predicate defined for configuration list \"list\" in path.",
142141
"Schema location \"/defs:l1\", line number 1.");
143142

144143
TEST_ERROR_XML2("",
145144
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/t:cont/t:1l", LY_EVALID);
146-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:1l\" value - syntax error.",
147-
"Schema location \"/defs:l1\", line number 1.");
148-
CHECK_LOG_CTX("Invalid character 't'[9] of expression '/t:cont/t:1l'.",
145+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont/t:1l\" value - syntax error: Invalid character 't'[9] of expression '/t:cont/t:1l'.",
149146
"Schema location \"/defs:l1\", line number 1.");
150147

151148
TEST_ERROR_XML2("",
152149
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/t:cont:t:1l", LY_EVALID);
153-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont:t:1l\" value - syntax error.",
154-
"Schema location \"/defs:l1\", line number 1.");
155-
CHECK_LOG_CTX("Invalid character ':'[8] of expression '/t:cont:t:1l'.",
150+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:cont:t:1l\" value - syntax error: Invalid character ':'[8] of expression '/t:cont:t:1l'.",
156151
"Schema location \"/defs:l1\", line number 1.");
157152

158153
TEST_ERROR_XML2("",
159154
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l1", "/xdf:cont/xdf:invalid/xdf:path", LY_EVALID);
160-
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:cont/xdf:invalid/xdf:path\" value - semantic error.",
161-
"Schema location \"/defs:l1\", line number 1.");
162-
CHECK_LOG_CTX("Not found node \"invalid\" in path.",
155+
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:cont/xdf:invalid/xdf:path\" value - semantic error: Not found node \"invalid\" in path.",
163156
"Schema location \"/defs:l1\", line number 1.");
164157

165158
/* non-existing instances, instance-identifier is here in JSON format because it is already in internal
@@ -198,100 +191,72 @@ test_data_xml(void **state)
198191
/* more errors */
199192
TEST_ERROR_XML2("<llist xmlns=\"urn:tests:defs\">x</llist>",
200193
"defs", "xmlns:t=\"urn:tests:defs\"", "t:l1", "/t:llist[1", LY_EVALID);
201-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1\" value - syntax error.",
202-
"Schema location \"/defs:l1\", line number 1.");
203-
CHECK_LOG_CTX("Unexpected XPath expression end.",
194+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1\" value - syntax error: Unexpected XPath expression end.",
204195
"Schema location \"/defs:l1\", line number 1.");
205196

206197
TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"/>",
207198
"defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont[1]", LY_EVALID);
208-
CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont[1]\" value - semantic error.",
209-
"Schema location \"/defs:l1\", line number 1.");
210-
CHECK_LOG_CTX("Positional predicate defined for container \"cont\" in path.",
199+
CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont[1]\" value - semantic error: Positional predicate defined for container \"cont\" in path.",
211200
"Schema location \"/defs:l1\", line number 1.");
212201

213202
TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"/>",
214203
"defs", "xmlns:m=\"urn:tests:mod\"", "l1", "[1]", LY_EVALID);
215-
CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error.",
216-
"Schema location \"/defs:l1\", line number 1.");
217-
CHECK_LOG_CTX("Unexpected XPath token \"[\" (\"[1]\"), expected \"Operator(Path)\".",
204+
CHECK_LOG_CTX("Invalid instance-identifier \"[1]\" value - syntax error: Unexpected XPath token \"[\" (\"[1]\"), expected \"Operator(Path)\".",
218205
"Schema location \"/defs:l1\", line number 1.");
219206

220207
TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"><l2/></cont>",
221208
"defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont/m:l2[l2='1']", LY_EVALID);
222-
CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[l2='1']\" value - syntax error.",
223-
"Schema location \"/defs:l1\", line number 1.");
224-
CHECK_LOG_CTX("Prefix missing for \"l2\" in path.",
209+
CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[l2='1']\" value - syntax error: Prefix missing for \"l2\" in path.",
225210
"Schema location \"/defs:l1\", line number 1.");
226211

227212
TEST_ERROR_XML2("<cont xmlns=\"urn:tests:mod\"><l2/></cont>",
228213
"defs", "xmlns:m=\"urn:tests:mod\"", "l1", "/m:cont/m:l2[m:l2='1']", LY_EVALID);
229-
CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[m:l2='1']\" value - semantic error.",
230-
"Schema location \"/defs:l1\", line number 1.");
231-
CHECK_LOG_CTX("List predicate defined for leaf \"l2\" in path.",
214+
CHECK_LOG_CTX("Invalid instance-identifier \"/m:cont/m:l2[m:l2='1']\" value - semantic error: List predicate defined for leaf \"l2\" in path.",
232215
"Schema location \"/defs:l1\", line number 1.");
233216

234217
TEST_ERROR_XML2("<llist xmlns=\"urn:tests:defs\">1</llist><llist xmlns=\"urn:tests:defs\">2</llist>",
235218
"defs", "xmlns:t=\"urn:tests:defs\"", "t:l1", "/t:llist[4]", LY_EVALID);
236-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[4]\" value - semantic error.",
237-
"Schema location \"/defs:l1\", line number 1.");
238-
CHECK_LOG_CTX("Positional predicate defined for configuration leaf-list \"llist\" in path.",
219+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[4]\" value - semantic error: Positional predicate defined for configuration leaf-list \"llist\" in path.",
239220
"Schema location \"/defs:l1\", line number 1.");
240221

241222
TEST_ERROR_XML2("",
242223
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/t:llist[6]", LY_EVALID);
243-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[6]\" value - semantic error.",
244-
"Schema location \"/defs:l2\", line number 1.");
245-
CHECK_LOG_CTX("No module connected with the prefix \"t\" found (prefix format XML prefixes).",
224+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[6]\" value - semantic error: No module connected with the prefix \"t\" found (prefix format XML prefixes).",
246225
"Schema location \"/defs:l2\", line number 1.");
247226

248227
TEST_ERROR_XML2("<list xmlns=\"urn:tests:defs\"><id>1</id><value>x</value></list>",
249228
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list[xdf:value='x']", LY_EVALID);
250-
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:value='x']\" value - semantic error.",
251-
"Schema location \"/defs:l2\", line number 1.");
252-
CHECK_LOG_CTX("Key expected instead of leaf \"value\" in path.",
229+
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:value='x']\" value - semantic error: Key expected instead of leaf \"value\" in path.",
253230
"Schema location \"/defs:l2\", line number 1.");
254231

255232
TEST_ERROR_XML2("",
256233
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list[.='x']", LY_EVALID);
257-
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[.='x']\" value - semantic error.",
258-
"Schema location \"/defs:l2\", line number 1.");
259-
CHECK_LOG_CTX("Leaf-list predicate defined for list \"list\" in path.",
234+
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[.='x']\" value - semantic error: Leaf-list predicate defined for list \"list\" in path.",
260235
"Schema location \"/defs:l2\", line number 1.");
261236

262237
TEST_ERROR_XML2("<llist xmlns=\"urn:tests:defs\">1</llist>",
263238
"defs", "xmlns:t=\"urn:tests:defs\"", "t:l1", "/t:llist[.='x']", LY_EVALID);
264-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='x']\" value - semantic error.",
239+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='x']\" value - semantic error: Invalid type uint32 value \"x\".",
265240
"Schema location \"/defs:l1\", line number 1.");
266-
CHECK_LOG_CTX("Invalid type uint32 value \"x\".",
267-
"Schema location \"/defs:llist\", line number 1.");
268241

269242
TEST_ERROR_XML2("",
270243
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/t:llist[1][2]", LY_EVALID);
271-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1][2]\" value - syntax error.",
272-
"Schema location \"/defs:l2\", line number 1.");
273-
CHECK_LOG_CTX("Unparsed characters \"[2]\" left at the end of path.",
244+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[1][2]\" value - syntax error: Unparsed characters \"[2]\" left at the end of path.",
274245
"Schema location \"/defs:l2\", line number 1.");
275246

276247
TEST_ERROR_XML2("",
277248
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/t:llist[.='a'][.='b']", LY_EVALID);
278-
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='a'][.='b']\" value - syntax error.",
279-
"Schema location \"/defs:l2\", line number 1.");
280-
CHECK_LOG_CTX("Unparsed characters \"[.='b']\" left at the end of path.",
249+
CHECK_LOG_CTX("Invalid instance-identifier \"/t:llist[.='a'][.='b']\" value - syntax error: Unparsed characters \"[.='b']\" left at the end of path.",
281250
"Schema location \"/defs:l2\", line number 1.");
282251

283252
TEST_ERROR_XML2("<list xmlns=\"urn:tests:defs\"><id>1</id><value>x</value></list>",
284253
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list[xdf:id='1'][xdf:id='2']/xdf:value", LY_EVALID);
285-
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list[xdf:id='1'][xdf:id='2']/xdf:value\" value - syntax error.",
286-
"Schema location \"/defs:l2\", line number 1.");
287-
CHECK_LOG_CTX("Duplicate predicate key \"id\" in path.",
254+
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.",
288255
"Schema location \"/defs:l2\", line number 1.");
289256

290257
TEST_ERROR_XML2("",
291258
"defs", "xmlns:xdf=\"urn:tests:defs\"", "xdf:l2", "/xdf:list2[xdf:id='1']/xdf:value", LY_EVALID);
292-
CHECK_LOG_CTX("Invalid instance-identifier \"/xdf:list2[xdf:id='1']/xdf:value\" value - semantic error.",
293-
"Schema location \"/defs:l2\", line number 1.");
294-
CHECK_LOG_CTX("Predicate missing for a key of list \"list2\" in path.",
259+
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.",
295260
"Schema location \"/defs:l2\", line number 1.");
296261
}
297262

0 commit comments

Comments
 (0)