This article describes how to set a custom Error message in case the EDIT callback reports an error.


For example, assume we have the following simplified but functional YANG module and we are making a SIL-SA code for this module as follow:


> make_sil_sa_dir error-example --sil-edit2 --sil-get2



module error-example {
  namespace "http://netconfcentral.org/ns/error-example";
  prefix "err";

  revision 2021-11-19 {
    description
      "Example module";
  }

  container test-silsa-errors {                      // EDIT2 CB
    presence "Presence";

    leaf test-error {
      type string;
    }
  }
}


In order to set a custom Error Message to be sent to the server the following API can be used:


/* Typedef of the Set Error Message API */
void
    sil_sa_set_error_msg (rpc_msg_t *msg,
                          const xmlChar *strval)

EXAMPLE


Assume the SIL-SA code reports an error in case the test-error leaf creation and when the value of a new leaf is force-error.

In this case there is an API sil_sa_set_error_msg() to set up a custom error to be returned to the server.



            if (child_val &&
                !xml_strcmp(VAL_STR(child_val), (const xmlChar *)"force-error")) {

                /* TRIGGER ERROR */
                res = ERR_NCX_OPERATION_NOT_SUPPORTED;

                sil_sa_set_error_msg(msg,
                                     (const xmlChar *)"SOME CUSTOM ERROR MSG");
            }


Thus, as a result of the following operation the SIL-SA agent will produce an error with a custom error message:


  <edit-config>
    <target>
      <candidate/>
    </target>
    <config>
      <test-silsa-errors xmlns="http://netconfcentral.org/ns/error-example">
        <test-error>force-error</test-error>
      </test-silsa-errors>
    </config>
  </edit-config>

After the final <commit> operation the SIL-SA code will be invoked and the SIL-SA code will return an error to the server with a custom error message as can be seen in the following log from the server:


agt_ycontrol: Got <ycontrol> message:
yctl:ycontrol {
  message-id 4
  message-type subsys-response
  server-id server1
  subsys-id subsys1
  service-id sil-sa
  error {
    error-number 273
    transaction-id 1476838
    error-message 'SOME CUSTOM ERROR MSG'
    error-index 1
  }
}

ycontrol_msg: sending server-event # 5 for sil-sa
ses_msg: send 1.1 buff:479for s:3

trace_buff:

#469
<?xml version="1.0" encoding="UTF-8"?>
<ycontrol xmlns="http://yumaworks.com/ns/yumaworks-ycontrol">
 <message-id>5</message-id>
 <message-type>server-event</message-type>
 <server-id>server1</server-id>
 <subsys-id>subsys1</subsys-id>
 <service-id>sil-sa</service-id>
 <payload>
  <sil-sa xmlns="http://yumaworks.com/ns/yumaworks-sil-sa">
   <cancel-transaction>
    <transaction-id>1476838</transaction-id>
   </cancel-transaction>
  </sil-sa>
 </payload>
</ycontrol>
agt_sil: send <cancel-transaction> to subsys 'subsys1' OK
agt_top: end dispatch yumaworks-ycontrol:ycontrol
ses_msg: free msg 0x7f70ac000f90 for session 3
ycontrol_mode_done for TXID '1476838'
agt_val: exit ncxserver YControl mode
agt_record_error for session 5:
agt_val: remote SIL commit phase failed (operation not supported)
agt_val: Finished remote SIL commit phase

Start full rollback of transaction 1476838: 1 edit on running config
Rollback transaction 1476838, create edit on error-example:test-silsa-errors
SIL-SA Rollback Complete callbacks OK
agt_sil: end transaction NULL txcb
ses_msg: send 1.0 buff:412 for s:5

trace_buff:
Content-Type: application/json
Status: 501 Not Implemented
Cache-Control: no-cache
Pragma: no-cache

{
 "ietf-restconf:errors": {
  "error": [
   {
    "error-type":"application",
    "error-tag":"operation-not-supported",
    "error-app-tag":"no-support",
    "error-path":"/err:test-silsa-errors",
    "error-message":"SOME CUSTOM ERROR MSG",
    "error-info": {
     "error-number":273
    }
   }
  ]
 }
}
agt_cb: Enter run_command_complete
agt_cb: Enter run_trans_complete




For complete example SIL-SA code, refer to the attachments.