Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Misleading error message when opening .yml file #2889

Open
2 tasks done
ndormann opened this issue Apr 10, 2024 · 2 comments · May be fixed by #2890
Open
2 tasks done

[Bug] Misleading error message when opening .yml file #2889

ndormann opened this issue Apr 10, 2024 · 2 comments · May be fixed by #2890
Labels
bug Something isn't working

Comments

@ndormann
Copy link

🐛 Bug

Description

The error message doesn't reflect that Hydra only accepts .yml files. The error message states "Cannot find primary config 'config.yml'" which hints at a problem with an incorrect path setup or a missing file. However, the config file exists and the path is correct. Only the file ending is not supported.

Checklist

  • I checked on the latest version of Hydra
  • I created a minimal repro (See this for tips).

To reproduce

** Minimal Code/Config snippet to reproduce **
from hydra import initialize, compose

with initialize(version_base=None, config_path="cloud_app/conf"):
cfg = compose("config.yml",overrides=["+db=mysql"])
print(cfg)

** Stack trace/error message **

MissingConfigException: Cannot find primary config 'config.yml'. Check that it's in your config search path.

Config search path:
	provider=hydra, path=pkg://hydra.conf
	provider=main, path=file:///home/user/notebooks/cloud_app/conf
	provider=schema, path=structured://

Expected Behavior

Output appropriate Error Message:

  • WrongFileEndingException: Only .yaml files are expected as config files.

System information

  • Hydra Version : 1.3.2
  • Python version : 3.9.19
  • Virtual environment type and version : conda 4.12.0
  • Operating system : ubuntu

Related Issues and PRs

Previous discussions to support .yml or not (concluded not to support for now): #398 #1050
Add note in documentation: #1298

@ndormann ndormann added the bug Something isn't working label Apr 10, 2024
@odelalleau
Copy link
Collaborator

It's not entirely trivial to fix in the general case due to how it's currently implemented, but I agree this is confusing.

What would be easy is to catch the ".yml" usage and raise a clear exception when it happens => we should probably start with that. Something like

--- a/hydra/plugins/config_source.py
+++ b/hydra/plugins/config_source.py
@@ -119,7 +119,10 @@ class ConfigSource(Plugin):
     @staticmethod
     def _normalize_file_name(filename: str) -> str:
         supported_extensions = [".yaml"]
-        if not version.base_at_least("1.2"):
+        if version.base_at_least("1.2"):
+            if filename.endswith(".yml"):
+                raise RuntimeError("bad extension")
+        else:
             supported_extensions.append(".yml")
             if filename.endswith(".yml"):
                 deprecation_warning(

(feel free to submit a clean PR if you want to)

@ndormann
Copy link
Author

Thank you, I have adopted your idea and submitted a corresponding PR.
Tests are failing, but I assume that is a general problem with your CI at the moment?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants