@@ -1140,13 +1140,17 @@ static LY_ERR
11401140lyd_validate_minmax (const struct lyd_node * first , const struct lyd_node * parent , const struct lysc_node * snode ,
11411141 uint32_t min , uint32_t max , uint32_t val_opts )
11421142{
1143+ LY_ERR rc = LY_SUCCESS ;
11431144 uint32_t count = 0 ;
1144- struct lyd_node * iter ;
1145+ struct lyd_node * iter , * last_iter = NULL ;
11451146 const struct lysc_when * disabled ;
1147+ char * log_path ;
1148+ int r ;
11461149
11471150 assert (min || max );
11481151
11491152 LYD_LIST_FOR_INST (first , snode , iter ) {
1153+ last_iter = iter ;
11501154 ++ count ;
11511155
11521156 if (min && (count == min )) {
@@ -1182,32 +1186,52 @@ 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+ /* set log path */
1191+ if (last_iter ) {
1192+ /* standard data path */
1193+ LOG_LOCSET (NULL , last_iter );
11911194 } 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 ;
1195+ /* data path with last schema node name or only the schema node if !parent */
1196+ if (lyd_node_module (parent ) != snode -> module ) {
1197+ r = asprintf (& log_path , "/%s:%s" , snode -> module -> name , snode -> name );
1198+ } else {
1199+ r = asprintf (& log_path , "/%s" , snode -> name );
1200+ }
1201+ if (r == -1 ) {
1202+ LOGMEM_RET (snode -> module -> ctx );
1203+ }
1204+ ly_log_location (NULL , parent , log_path , NULL );
1205+ free (log_path );
11961206 }
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 );
1207+
1208+ if (min ) {
1209+ if (val_opts & LYD_VALIDATE_OPERATIONAL ) {
1210+ /* only a warning */
1211+ LOGWRN (snode -> module -> ctx , "Too few \"%s\" instances." , snode -> name );
1212+ } else {
1213+ LOGVAL_APPTAG (snode -> module -> ctx , "too-few-elements" , LY_VCODE_NOMIN , snode -> name );
1214+ rc = LY_EVALID ;
1215+ }
1216+ } else if (max ) {
1217+ if (val_opts & LYD_VALIDATE_OPERATIONAL ) {
1218+ /* only a warning */
1219+ LOGWRN (snode -> module -> ctx , "Too many \"%s\" instances." , snode -> name );
1220+ } else {
1221+ LOGVAL_APPTAG (snode -> module -> ctx , "too-many-elements" , LY_VCODE_NOMAX , snode -> name );
1222+ rc = LY_EVALID ;
1223+ }
1224+ }
1225+
1226+ /* revert log path */
1227+ if (last_iter ) {
12021228 LOG_LOCBACK (0 , 1 );
12031229 } 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 ;
1230+ ly_log_location_revert (0 , parent ? 1 : 0 , 1 , 0 );
12081231 }
12091232 }
1210- return LY_SUCCESS ;
1233+
1234+ return rc ;
12111235}
12121236
12131237/**
0 commit comments