Skip to content

Commit 4d735f5

Browse files
committed
lyd_validate_minmax(): always return a valid data path
The current code never returns a data path, only a schema path for failures where the 'min' value is not reached. Integrators may need to obtain both a LIST key as well as the leaf name to present proper error messages. When we don't have a full valid data path, the code now will return the parent's data path with the current schema node name appended. This fix was inspired by porting of SONiC's sonic-mgmt-common which is utilizing this feature which previously worked with libyang1. Signed-off-by: Brad House <[email protected]>
1 parent 03e294d commit 4d735f5

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/validation.c

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,7 +1142,9 @@ lyd_validate_minmax(const struct lyd_node *first, const struct lyd_node *parent,
11421142
{
11431143
uint32_t count = 0;
11441144
struct lyd_node *iter;
1145+
11451146
const struct lysc_when *disabled;
1147+
LY_ERR rv = LY_SUCCESS;
11461148

11471149
assert(min || max);
11481150

@@ -1182,32 +1184,33 @@ lyd_validate_minmax(const struct lyd_node *first, const struct lyd_node *parent,
11821184
max = 0;
11831185
}
11841186

1185-
if (min) {
1186-
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1187-
/* only a warning */
1188-
LOG_LOCSET(snode, NULL);
1189-
LOGWRN(snode->module->ctx, "Too few \"%s\" instances.", snode->name);
1190-
LOG_LOCBACK(1, 0);
1187+
if (min || max) {
1188+
1189+
if (min) {
1190+
char suffix_path[256];
1191+
snprintf(suffix_path, sizeof(suffix_path), "/%s", snode->name);
1192+
1193+
ly_log_location(NULL, parent, suffix_path, NULL);
1194+
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1195+
LOGWRN(snode->module->ctx, "Too few \"%s\" instances.", snode->name);
1196+
} else {
1197+
LOGVAL_APPTAG(snode->module->ctx, "too-few-elements", LY_VCODE_NOMIN, snode->name);
1198+
}
1199+
ly_log_location_revert(0, 1, 1, 0);
11911200
} else {
1192-
LOG_LOCSET(snode, NULL);
1193-
LOGVAL_APPTAG(snode->module->ctx, "too-few-elements", LY_VCODE_NOMIN, snode->name);
1194-
LOG_LOCBACK(1, 0);
1195-
return LY_EVALID;
1201+
ly_log_location(NULL, iter, NULL, NULL);
1202+
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1203+
LOGWRN(snode->module->ctx, "Too many \"%s\" instances.", snode->name);
1204+
} else {
1205+
LOGVAL_APPTAG(snode->module->ctx, "too-many-elements", LY_VCODE_NOMAX, snode->name);
1206+
}
1207+
ly_log_location_revert(0, 1, 0, 0);
11961208
}
1197-
} else if (max) {
1198-
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1199-
/* only a warning */
1200-
LOG_LOCSET(NULL, iter);
1201-
LOGWRN(snode->module->ctx, "Too many \"%s\" instances.", snode->name);
1202-
LOG_LOCBACK(0, 1);
1203-
} else {
1204-
LOG_LOCSET(NULL, iter);
1205-
LOGVAL_APPTAG(snode->module->ctx, "too-many-elements", LY_VCODE_NOMAX, snode->name);
1206-
LOG_LOCBACK(0, 1);
1207-
return LY_EVALID;
1209+
if (!(val_opts & LYD_VALIDATE_OPERATIONAL)) {
1210+
rv = LY_EVALID;
12081211
}
12091212
}
1210-
return LY_SUCCESS;
1213+
return rv;
12111214
}
12121215

12131216
/**

0 commit comments

Comments
 (0)