omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.88k stars 98 forks source link

Improve error message for relative interpolations #1126

Open MatteoVoges opened 9 months ago

MatteoVoges commented 9 months ago

Is your feature request related to a problem? Please describe.

Current error message

from omegaconf import OmegaConf

input = """
a:
  a: 
    a: ${..b}
"""

config = OmegaConf.create(input)
try:
    OmegaConf.resolve(config)
except Exception as e:
    print(e)
# >>> Interpolation key 'b' not found

We see that the dots / the relative path doesn't show up in the error message. This makes it really hard to debug not found keys.

Describe the solution you'd like

There are several ways to solve this problem and to improve the error message:

  1. show the full path of the key that couldn't found, e.g. : Interpolation key 'a.b' not found
  2. show the relative path of the key like in the interpolation: Interpolation key '..b' not found
  3. show the nodes path, where the interpolation is defined, e.g: Interpolation key 'a.b' not found at node a.a.a

I would prefer a mix of these options, but I like option 3 the most, because there its clear which key is missing and where to look to fix the interpolation.

odelalleau commented 9 months ago

I think the ideal message would display: