Skip to content

Commit 529a594

Browse files
michalvaskobradh352
andcommitted
union UPDATE use err-app-tag if suitable
Refs #2356 Co-authored-by: Brad House <[email protected]>
1 parent 76a439f commit 529a594

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/plugins_types/union.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,9 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
267267
LY_ARRAY_COUNT_TYPE u;
268268
struct ly_err_item **errs = NULL, *e;
269269
uint32_t *prev_lo, temp_lo = 0;
270-
char *msg = NULL;
270+
char *msg = NULL, *err_app_tag = NULL;
271271
int msg_len = 0;
272+
ly_bool use_err_app_tag = 0;
272273

273274
*err = NULL;
274275

@@ -306,12 +307,27 @@ union_find_type(const struct ly_ctx *ctx, struct lysc_type_union *type_u, struct
306307
continue;
307308
}
308309

310+
/* use an app-tag if all the types set it or set none */
311+
if (errs[u]->apptag) {
312+
if (!err_app_tag) {
313+
err_app_tag = strdup(errs[u]->apptag);
314+
LY_CHECK_ERR_GOTO(!err_app_tag, ret = LY_EMEM, cleanup);
315+
use_err_app_tag = 1;
316+
} else if (strcmp(errs[u]->apptag, err_app_tag)) {
317+
use_err_app_tag = 0;
318+
}
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+
if (!use_err_app_tag) {
327+
free(err_app_tag);
328+
err_app_tag = NULL;
329+
}
330+
ret = ly_err_new(err, LY_EVALID, LYVE_DATA, NULL, err_app_tag, "%s", msg);
315331
} else if (type_idx) {
316332
*type_idx = u;
317333
}

0 commit comments

Comments
 (0)