@@ -150,17 +150,26 @@ lyb_parse_union(const void *lyb_data, size_t lyb_data_len, uint32_t *type_idx, c
150150 }
151151}
152152
153+ /**
154+ * @brief For leafref failures, ensure the appropriate error is propagated, not a type validation failure.
155+ *
156+ * @param[in] ctx_node Context node for prefix resolution.
157+ * @param[in,out] err Error record to be updated
158+ * @param[in] type leafref type used to extract target path
159+ * @param[in] value value attempting to be stored
160+ * @param[in] value_len Length of value that was attempted to be stored.
161+ */
153162static void
154- union_lref_error_rewrite (const struct lyd_node * ctx_node , struct ly_err_item * err , struct lysc_type * type , const void * value , size_t value_len )
163+ union_update_lref_err (const struct lyd_node * ctx_node , struct ly_err_item * err , const struct lysc_type * type , const void * value , size_t value_len )
155164{
156- struct lysc_type_leafref * lref ;
165+ const struct lysc_type_leafref * lref ;
157166 char * valstr = NULL ;
158167
159168 if ((err == NULL ) || (type -> basetype != LY_TYPE_LEAFREF )) {
160169 return ;
161170 }
162171
163- lref = (struct lysc_type_leafref * )type ;
172+ lref = (const struct lysc_type_leafref * )type ;
164173 free (err -> apptag );
165174 err -> apptag = strdup ("instance-required" );
166175
@@ -217,7 +226,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
217226 memset (& subvalue -> value , 0 , sizeof subvalue -> value );
218227
219228 /* if this is a leafref, lets make sure we propagate the appropriate error, and not a type validation failure */
220- union_lref_error_rewrite (ctx_node , * err , type_u -> types [ti ], value , value_len );
229+ union_update_lref_err (ctx_node , * err , type_u -> types [ti ], value , value_len );
221230 return rc ;
222231 }
223232
@@ -258,9 +267,7 @@ union_store_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, uint3
258267 memset (& subvalue -> value , 0 , sizeof subvalue -> value );
259268
260269 /* if this is a leafref, lets make sure we propagate the appropriate error, and not a type validation failure */
261- if (type -> basetype == LY_TYPE_LEAFREF ) {
262- union_lref_error_rewrite (ctx_node , * err , type , value , value_len );
263- }
270+ union_update_lref_err (ctx_node , * err , type , value , value_len );
264271 return rc ;
265272 }
266273
0 commit comments