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

OmegaConf.to_yaml fails when passed a plain str #560

Closed
Jasha10 opened this issue Feb 23, 2021 · 2 comments · Fixed by #568
Closed

OmegaConf.to_yaml fails when passed a plain str #560

Jasha10 opened this issue Feb 23, 2021 · 2 comments · Fixed by #568
Labels
bug Something isn't working

Comments

@Jasha10
Copy link
Collaborator

Jasha10 commented Feb 23, 2021

You can pass OmegaConf.to_yaml a dict or list with no problem:

>>> OmegaConf.to_yaml(["abc"])
'- abc\n'

But if you pass a str, you get an AssertionError:

>>> OmegaConf.to_yaml("abc")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/Jasha10/omegaconf/omegaconf/omegaconf.py", line 815, in to_yaml
    cfg = _ensure_container(cfg)
  File "/home/Jasha10/omegaconf/omegaconf/_utils.py", line 694, in _ensure_container
    assert OmegaConf.is_config(target)
AssertionError

Desired Behavior:

  • a more informative error message, such as "to_yaml got a bad input of type <class 'str'>".

Does it make sense to do anything besides throwing an error? The output of the to_yaml function is a string, so I'm not sure what would be the correct way to handle inputs that are strings.

@Jasha10 Jasha10 added the bug Something isn't working label Feb 23, 2021
@omry
Copy link
Owner

omry commented Feb 24, 2021

Yes, I think it makes sense. assertion errors should be not be raised for bad user inputs, only for internal bugs.
I think a plain ValueError explaining the valid inputs to the function will be good enough.

@Jasha10
Copy link
Collaborator Author

Jasha10 commented Feb 24, 2021

I think a plain ValueError explaining the valid inputs to the function will be good enough.

Sounds good.

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