cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1632
Views
0
Helpful
10
Replies

custom error-message for datatypes

Iman1
Level 1
Level 1

Hi

 

Is there any way to define custom error-message for data types in yang? For example:

 

type inet:ipv4-address {
error-message "Invalid IPv4 address for loopback0";
}

 

PS - the above produces an error: unexpected keyword 'error-message'

10 Replies 10

joepak
Cisco Employee
Cisco Employee
Hi,

Take a look at what was provided in RFC7950 - YANG:

7.5.4. The must's Substatements

+---------------+---------+-------------+
| substatement | section | cardinality |
+---------------+---------+-------------+
| description | 7.21.3 | 0..1 |
| error-app-tag | 7.5.4.2 | 0..1 |
| error-message | 7.5.4.1 | 0..1 |
| reference | 7.21.4 | 0..1 |
+---------------+---------+-------------+

7.5.4.1. The "error-message" Statement

The "error-message" statement, which is optional, takes a string as
an argument. If the constraint evaluates to "false", the string is
passed as <error-message> in the <rpc-error> in NETCONF.

7.5.4.2. The "error-app-tag" Statement

The "error-app-tag" statement, which is optional, takes a string as
an argument. If the constraint evaluates to "false", the string is
passed as <error-app-tag> in the <rpc-error> in NETCONF.

7.5.4.3. Usage Example of must and error-message

container interface {
leaf ifType {
type enumeration {
enum ethernet;
enum atm;
}
}
leaf ifMTU {
type uint32;
}
must 'ifType != "ethernet" or ifMTU = 1500' {
error-message "An Ethernet MTU must be 1500";
}
must 'ifType != "atm" or'
+ ' (ifMTU <= 17966 and ifMTU >= 64)' {
error-message "An ATM MTU must be 64 .. 17966";
}
}

10.3.1.1. Usage Example

list interface {
key "name type";
leaf name { ... }
leaf type { ... }
leaf enabled {
type boolean;
}
...
}

container mgmt-interface {
leaf name {
type leafref {
path "/interface/name";
}
}
leaf type {
type leafref {
path "/interface[name=current()/../name]/type";
}
must 'deref(.)/../enabled = "true"' {
error-message
"The management interface cannot be disabled.";
}
}
}


It seems a string must be configured in order for 'error-message' to work. Are you trying to set certain restraints on the ipv4-address?

Thanks, yes I have seen that part of RFC but it seems in all the examples error-message is applicable when a condition is evaluated on datatype (for example: range, pattern, etc.). I'm not trying to impose further conditions on "inet:ipv4-address", rather want to just customize the error message that NSO returns to NB API when an invalid IP address is sent. By default, NSO's error-message returned to NB API contains the internal xpath to the IPv4 address in question, I want to customize that to a more generic error message. 

joepak
Cisco Employee
Cisco Employee
Hmm. Makes sense. For display purposes, can you provide a sample of what you see now when an error occurs? Just to make more sense of it.

Here's a sample of error-message NSO would return to NB API by default:

 

"error-message": "invalid value for: loopback0v4 in /myservice:myservice[myservice:device='Router24']/myservice:loopbacks/myservice:loopback0v4: \"10.10.10.1000\" is not a valid value."

joepak
Cisco Employee
Cisco Employee
So..

The only thing I can find within the NSO install directory is the following:


src/ncs/errors/errcode.xml:343: "{lexical-unicode}" is not a valid value.

src/ncs/errors/errcode.xml:349: {native-val} is not a valid value.

src/ncs/errors/errcode.xml:400: "{lexical-val}" is not a valid value.


In which leads me to believe it may not be something that is easily adjustable since I think it is predefined within NSO. I could be wrong, but take a look at the errcode.xml:






This error type denotes a type error. It is generated when an

invalid value is specified for a certain leaf.









{native-val} is not a valid value.





joepak
Cisco Employee
Cisco Employee

Sorry, it filtered the other info. But bad_value us explained as:

This error type denotes a type error. It is generated when an
invalid value is specified for a certain leaf.

 

which leads to the following errcodes.

 

 

Another thing would be, what is the use-case here? More customization? To me it seems straight forward as to what is wrong, but I understand use cases my vary.

yeah good find... I'm not sure how errcode.xml is imported and used inside ncs. If someone could shed more light on it, that would be great... I wish there was some documentation around it (maybe there is?)...

 

The use-case is simple... we don't necessarily want NSO's default error-messages which refer to the internal structure of service yang to be passed to a NB system/user. Ability to customize/generalize the error text returned to NB systems/users who are unaware of NSO details is very much desired. 

joepak
Cisco Employee
Cisco Employee
I’ll see what I can do for you.

Thanks Joe

joepak
Cisco Employee
Cisco Employee

Hi,

 

So..As far as I know..only some errors can  be altered. If you go to your NSO install directory and go into the man pages > man3 > confd_lib_dp, you can check out a section called 'Error Formatting Callback'. But that is all I can find at the moment. I checked it out myself and I'm not too familiar with this, but as far as I can find, this is the closest to what you are requesting.

 

Hope this helps!

 

Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the NSO Developer community: