Assertion '(&values[i])->type == C_UINT16' failed

I have yang definition for configuring vlan range:
leaf-list vid {
tailf:info “range of vlan-ids (separated by ,or-)”;
tailf:cli-range-list-syntax;
type union {
type uint16 {
tailf:info “vlan id <2-4094>”;
range “2…4094”;
}
type string {
tailf:info “range of vlan id separated by either ‘-’ or ‘,’”;
}
}
}

In my daemon, I am trying to do the following:
confd_value_t *values;

/* add/udpate for vlan-range */
status = cdb_cd(rsock, "/link/vlan-map[%d]", vlan_p->cos_id);
if (status == CONFD_ERR) {
    return false;
}
if (cdb_get_list(rsock, &values, &n, "vid") != CONFD_OK) {
    syslog(LOG_DEBUG, "%s: no entries for this cos", __FUNCTION__);
    n = 0;
}
for (i = 0; i < n; i++) {
    syslog(LOG_DEBUG, "%s: %d) %d\n", __FUNCTION__, i, CONFD_GET_UINT16(&values[i]);
}

I am getting a core because of CONFD_GET_UINT16 when I try to test a negative scenario of configuring ‘0’ or ‘-1’ for the vid.

I am wondering what I am missing here.

I have range “2…4094”;
So, yang should have rejected when I try to configure 0 or -1 or 1. Why I am getting subscription call?

But the uint16 with that range is only the first member of a YANG union, with the other member being an unrestricted ‘string’ (i.e. “anything goes”). Per the YANG spec, values are tried against the union members in the order they are defined, and thus any value that doesn’t match your uint16 will result in match for the string, and you will get a C_BUF value which in the cases you mention will be “0”, “-1”, and “1”, respectively.

You may want to restrict the string with a ‘pattern’ (regexp) that formally declares what you say in the tailf:info.

Thank you for a detailed answer. Will try to add regex to the string as you suggested.