Skip to content

Commit dc3ac55

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 dc3ac55

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/validation.c

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,11 +1142,15 @@ 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+
struct lyd_node *any_valid = NULL;
1146+
char suffix_path[256] = "";
11451147
const struct lysc_when *disabled;
1148+
LY_ERR rv = LY_SUCCESS;
11461149

11471150
assert(min || max);
11481151

11491152
LYD_LIST_FOR_INST(first, snode, iter) {
1153+
any_valid = iter;
11501154
++count;
11511155

11521156
if (min && (count == min)) {
@@ -1182,32 +1186,28 @@ lyd_validate_minmax(const struct lyd_node *first, const struct lyd_node *parent,
11821186
max = 0;
11831187
}
11841188

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);
1189+
if (min || max) {
1190+
snprintf(suffix_path, sizeof(suffix_path), "/%s", snode->name);
1191+
ly_log_location(NULL, any_valid?any_valid:parent, any_valid?NULL:suffix_path, NULL);
1192+
if (min) {
1193+
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1194+
LOGWRN(snode->module->ctx, "Too few \"%s\" instances.", snode->name);
1195+
} else {
1196+
LOGVAL_APPTAG(snode->module->ctx, "too-few-elements", LY_VCODE_NOMIN, snode->name);
1197+
}
11911198
} 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;
1199+
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1200+
LOGWRN(snode->module->ctx, "Too many \"%s\" instances.", snode->name);
1201+
} else {
1202+
LOGVAL_APPTAG(snode->module->ctx, "too-many-elements", LY_VCODE_NOMAX, snode->name);
1203+
}
11961204
}
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;
1205+
ly_log_location_revert(0, 1, any_valid?0:1, 0);
1206+
if (!(val_opts & LYD_VALIDATE_OPERATIONAL)) {
1207+
rv = LY_EVALID;
12081208
}
12091209
}
1210-
return LY_SUCCESS;
1210+
return rv;
12111211
}
12121212

12131213
/**

0 commit comments

Comments
 (0)