I have a netconf server with a yang model that contains several configurational data. To exemplify, I have 3 unique ip addresses (i.e ip address of dev1, ip address of dev2, ip address of dev3) each of them corresponds to a leaf and they use same ipv4 validation which contains same error message.
The netconf server is connected to lighty.io. I would like to use RESTCONF with lighty and change those 3 fields at once. However, if an error comes up from yang validations, I would like to understand which leaf (which ip) causes error rather than seeing same error message. Is it possible to customize error-message for a single leaf?
This depends on what you mean by “yang validation”. If this is a restriction given by the type, the error-message reply attribute points to the leaf that failed; if it is a must statement, you can use custom error-message YANG statement like this:
must "value == 42" {
error-message "This value does not make sense.";
}
If you mean a validation callback, you can call confd_trans_seterr to set your own error message.
Let me explain more. I have two leafs: ip-address-device1, ip-address-device2. They are using my custom typedef called my-ip-validation with a custom pattern defined by me inside. Although they use the same pattern I would like to log different error-message like “ip address of device 1 is not valid” for first device and “ip address of device 2 is not valid” for second device. Is that possible somehow? The only thing that comes to my mind is to duplicate the patterns for each leaf although in fact they are the same patterns which does not look ideal solution.
You may provide a custom error message using the statement error-message, but there is nothing like “templating” so that it is different for two leaves using the same type. On the other hand, all error messages returned by a northbound interface indicate which leaf was being set to an invalid value; for RESTCONF it may look like
"error-message": "invalid value for: leaf1 in
/my-module:root/my-module:leaf1: custom-error-message"
(where custom-error-message is what you provide in the YANG module). So your error message is there, the path is there too. There are other options of customizing it using error formatting callbacks, but that does not appear to work for RESTCONF, I’m not sure why.