Skip to content

Commit

Permalink
union: propagate apptag error if all errors use the same apptag
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
bradh352 committed Feb 24, 2025
1 parent 76a439f commit 0ee3863
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/plugins_types/union.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
}

if (u == LY_ARRAY_COUNT(type_u->types)) {
const char *apptag = NULL;

/* create the full error */
if (subvalue->format == LY_VALUE_LYB) {
msg_len = asprintf(&msg, "Invalid LYB union value - no matching subtype found:\n");
Expand All @@ -306,12 +308,19 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
continue;
}

/* If all errors use the same apptag, propagate it */
if (u == 0) {
apptag = errs[u]->apptag;
} else if (apptag && (!errs[u]->apptag || (strcmp(errs[u]->apptag, apptag) != 0))) {
apptag = NULL;
}

msg = ly_realloc(msg, msg_len + 4 + strlen(type_u->types[u]->plugin->id) + 2 + strlen(errs[u]->msg) + 2);
LY_CHECK_ERR_GOTO(!msg, ret = LY_EMEM, cleanup);
msg_len += sprintf(msg + msg_len, " %s: %s\n", type_u->types[u]->plugin->id, errs[u]->msg);
}

ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, NULL, "%s", msg);
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, apptag ? strdup(apptag) : NULL, "%s", msg);
} else if (type_idx) {
*type_idx = u;
}
Expand Down

0 comments on commit 0ee3863

Please sign in to comment.