Skip to content

Commit 2970ac9

Browse files
committed
union: propagate apptag error if all errors use the same apptag
If a union references various different leafref paths, and all leafref paths are invalid, it is nice to have the apptag returned as instance-required. There may be other use cases... Signed-off-by: Brad House <[email protected]>
1 parent 76a439f commit 2970ac9

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/plugins_types/union.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
290290
}
291291

292292
if (u == LY_ARRAY_COUNT(type_u->types)) {
293+
const char *apptag = NULL;
294+
293295
/* create the full error */
294296
if (subvalue->format == LY_VALUE_LYB) {
295297
msg_len = asprintf(&msg, "Invalid LYB union value - no matching subtype found:\n");
@@ -306,12 +308,19 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
306308
continue;
307309
}
308310

311+
/* If all errors use the same apptag, propagate it */
312+
if (u == 0) {
313+
apptag = errs[u]->apptag;
314+
} else if (apptag && (!errs[u].apptag || (strcmp(errs[u].apptag, apptag) != 0))) {
315+
apptag = NULL;
316+
}
317+
309318
msg = ly_realloc(msg, msg_len + 4 + strlen(type_u->types[u]->plugin->id) + 2 + strlen(errs[u]->msg) + 2);
310319
LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup);
311320
msg_len += sprintf(msg + msg_len, " %s: %s\n", type_u->types[u]->plugin->id, errs[u]->msg);
312321
}
313322

314-
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg);
323+
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, apptag ? strdup(apptag) : NULL, "%s", msg);
315324
} else if (type_idx) {
316325
*type_idx = u;
317326
}

0 commit comments

Comments
 (0)