Using if-feature in tailf:callpoint is not supported?

I would like to conditionally define a transaction hook based on a feature.
So I’m using following syntax:

tailf:callpoint "some-hook" {
  if-feature "fp:MyFeature";
  tailf:transaction-hook "node";
}

tailf:callpoint "some-transaction-hook" {
  if-feature "fp:MyFeature";
  tailf:transaction-hook "node" {
    tailf:invocation-mode per-transaction;
  }
}

Oddly enough everything seemed to work fine. I overlooked the error message from confdc compiler until a few days later after I rebased and my build refused to continue.

The message is:

xyz.yang:8999: error: unexpected keyword 'if-feature'
xyz.yang:9004: error: unexpected keyword 'if-feature'

What’s wrong with this yang?

The extension statement tailf:callpoint does not allow if-feature as its child. Somewhat brute force approach to adding callpoints dynamically at compile time - if that’s what you are up to - is to have an annotation file per feature and add annotation files to the compiler command line as needed.

We accept “if-feature” under the “tailf:annotate” statement, so, another way that works is to use an annotation file and annotate the same XPath with two different features. Example:

feature feature1;
feature feature2;

  tailf:annotate "/x:dhcp" {
    if-feature feature1;
    tailf:callpoint some-hook; 
  }

  tailf:annotate "/x:dhcp" {
    if-feature feature2;
    tailf:callpoint some-transaction-hook;
  }

Note that here, the if-feature statement is only used by the backend code, it doesn’t result in a modified schema, from the data perspective. The front end user may be confused as to what each feature means, unless well documented. If the annotation files are not exposed, this won’t be an issue.

mvf’s response is another way of doing this without introducing the “if-feature” statement.

@nabil @mvf Thank you very much for explanation, I shall check these options.