Skip to content

Commit 6eb7963

Browse files
committed
lyd_validate_minmax(): always return a valid data path if available
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. Only if there is no parent (not a realworld issue, but the test system does this) will the schema path be used. 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 02126d7 commit 6eb7963

File tree

1 file changed

+26
-22
lines changed

1 file changed

+26
-22
lines changed

src/validation.c

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,6 +1143,7 @@ lyd_validate_minmax(const struct lyd_node *first, const struct lyd_node *parent,
11431143
uint32_t count = 0;
11441144
struct lyd_node *iter;
11451145
const struct lysc_when *disabled;
1146+
LY_ERR rv = LY_SUCCESS;
11461147

11471148
assert(min || max);
11481149

@@ -1182,32 +1183,35 @@ lyd_validate_minmax(const struct lyd_node *first, const struct lyd_node *parent,
11821183
max = 0;
11831184
}
11841185

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);
1186+
if (min || max) {
1187+
if (min) {
1188+
char suffix_path[256] = "";
1189+
1190+
if (parent != NULL) {
1191+
snprintf(suffix_path, sizeof(suffix_path), "/%s", snode->name);
1192+
}
1193+
1194+
ly_log_location((!parent) ? snode : NULL, parent, parent ? suffix_path : NULL, NULL);
1195+
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1196+
LOGWRN(snode->module->ctx, "Too few \"%s\" instances.", snode->name);
1197+
} else {
1198+
LOGVAL_APPTAG(snode->module->ctx, "too-few-elements", LY_VCODE_NOMIN, snode->name);
1199+
}
1200+
ly_log_location_revert((!parent) ? 1 : 0, parent ? 1 : 0, parent ? 1 : 0, 0);
11911201
} 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;
1202+
ly_log_location(NULL, iter, NULL, NULL);
1203+
if (val_opts & LYD_VALIDATE_OPERATIONAL) {
1204+
LOGWRN(snode->module->ctx, "Too many \"%s\" instances.", snode->name);
1205+
} else {
1206+
LOGVAL_APPTAG(snode->module->ctx, "too-many-elements", LY_VCODE_NOMAX, snode->name);
1207+
}
1208+
ly_log_location_revert(0, 1, 0, 0);
11961209
}
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;
1210+
if (!(val_opts & LYD_VALIDATE_OPERATIONAL)) {
1211+
rv = LY_EVALID;
12081212
}
12091213
}
1210-
return LY_SUCCESS;
1214+
return rv;
12111215
}
12121216

12131217
/**

0 commit comments

Comments
 (0)