Skip to content

Commit ed9a6f5

Browse files
committed
union: propagate apptag error if all non-NULL 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 ed9a6f5

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/plugins_types/union.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ 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+
ly_bool use_apptag = 0;
295+
293296
/* create the full error */
294297
if (subvalue->format == LY_VALUE_LYB) {
295298
msg_len = asprintf(&msg, "Invalid LYB union value - no matching subtype found:\n");
@@ -306,12 +309,21 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
306309
continue;
307310
}
308311

312+
/* Capture an apptag if one exists. We will propagate it if all set
313+
* apptags match, ignoring any NULL apptags. */
314+
if (apptag == NULL) {
315+
use_apptag = 1;
316+
apptag = errs[u]->apptag;
317+
} else if (apptag && errs[u]->apptag && (strcmp(errs[u]->apptag, apptag) != 0)) {
318+
use_apptag = 0;
319+
}
320+
309321
msg = ly_realloc(msg, msg_len + 4 + strlen(type_u->types[u]->plugin->id) + 2 + strlen(errs[u]->msg) + 2);
310322
LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup);
311323
msg_len += sprintf(msg + msg_len, " %s: %s\n", type_u->types[u]->plugin->id, errs[u]->msg);
312324
}
313325

314-
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg);
326+
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, use_apptag ? strdup(apptag) : NULL, "%s", msg);
315327
} else if (type_idx) {
316328
*type_idx = u;
317329
}

0 commit comments

Comments
 (0)