Skip to content

deref of an empty leafref reports further validation failures #2592

Open

Description

@jktjkt

Now that #2584 is fixed, libyang produces "surprising" diagnostics when deref() fails the require-instance true. Here's a small example:

module deref-arith {
  yang-version 1.1;
  namespace "urn:example:deref-arith";
  prefix da;

  list band {
    key name;
    leaf name { type string; }
    leaf lower { type uint32; mandatory true; }
    leaf upper { type uint32; mandatory true; }
  }

  list channel {
    key band;
    leaf band {
      type leafref { path "/band/name"; }
    }
    must "deref(band)/../upper - deref(band)/../lower >= 50" {
      error-message "Band is narrower than 50";
    }
  }
}
{
  "deref-arith:band": [
    { "name": "wide", "lower": 100, "upper": 200 }
  ],
  "deref-arith:channel": [
    { "band": "wide" },
    { "band": "missing" }
  ]
}

Here's how it fails. The first error message is expected, the second is, in my opinion, a superfluous one:

$ yanglint -t config deref-arith.yang data.json
libyang err : Invalid leafref value "missing" - no target instance "/band/name" with the same value. (/deref-arith:channel[band='missing']/band)
libyang err : Band is narrower than 50 (/deref-arith:channel[band='missing'])
YANGLINT[E]: Failed to parse input data file "data.json".

We bumped into this in a unit test of our internal project.

I wonder if it's possible (and standard-compliant) to return a better error message here. Please note that my target audience is not the author of the YANG model or someone writing the YANG data in JSON/XML/..., but someone who works with a CLI, who just made a typo in a leafref name, and who is confused by an error message complaining about a "too narrow channel".

Activity

  1. michalvasko commented on Oct 19, 2026

    @michalvasko
    Member

    The second message is the result of multi-error validation. The first error reports invalid band value and the second invalid channel must condition, for libyang the 2 are not connected. So, I am not sure what to improve.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    is:enhancementRequest for adding new feature or enahncing functionality.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions