cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Announcements

942
Views
0
Helpful
10
Replies
Iman1
Beginner

custom error-message for datatypes

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

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?