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

dvc.api.params_show: More helpful error handling #7926

Closed
dberenbaum opened this issue Jun 21, 2022 · 5 comments · Fixed by #7938
Closed

dvc.api.params_show: More helpful error handling #7926

dberenbaum opened this issue Jun 21, 2022 · 5 comments · Fixed by #7938
Assignees
Labels
A: api Related to the dvc.api p2-medium Medium priority, should be done, but less important ui user interface / interaction

Comments

@dberenbaum
Copy link
Contributor

Bug Report

Description

Doesn't show useful errors.

Reproduce

  1. git clone git@github.com:iterative/pipeline-conifguration.git
  2. cd pipeline-conifguration
  3. Start Python shell:
>>> import dvc.api
>>> dvc.api.params_show()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/dave/Code/dvc/dvc/api/params.py", line 267, in params_show
    return _postprocess(params)
  File "/Users/dave/Code/dvc/dvc/api/params.py", line 256, in _postprocess
    return processed[first(processed)]
KeyError: None

Expected

I'm guessing it fails because there's no dvc.yaml or params.yaml in the project root where the shell is started, but the error message doesn't help me understand this or how to fix it.

@daavoo
Copy link
Contributor

daavoo commented Jun 21, 2022

The error, in this case, can be avoided. Do you think it would be more useful to return an empty dict or rather raise an exception like No params found?

@dberenbaum
Copy link
Contributor Author

I think an error in this case? I doubt there's much reason to call params_show if you expect an empty dict.

What would happen if there was a params.yaml but no dvc.yaml found? What about the inverse?

@daavoo daavoo added A: api Related to the dvc.api ui user interface / interaction labels Jun 27, 2022
@daavoo
Copy link
Contributor

daavoo commented Jun 27, 2022

I think an error in this case? I doubt there's much reason to call params_show if you expect an empty dict.

I was thinking about returning an empty dict instead of raising an exception because dvc {X} show commands don't fail when there is nothing to return.

What would happen if there was a params.yaml but no dvc.yaml found?

The contents of params.yaml will be returned.

What about the inverse?

The KeyError point will be reached.

@daavoo daavoo linked a pull request Jun 27, 2022 that will close this issue
@dberenbaum dberenbaum added the p2-medium Medium priority, should be done, but less important label Jun 27, 2022
@dberenbaum
Copy link
Contributor Author

I was thinking about returning an empty dict instead of raising an exception because dvc {X} show commands don't fail when there is nothing to return.

Good point. I think we err on the side of not throwing errors in the CLI to avoid breaking CI scripts. If you feel the symmetry is important, I think it's fine to return an empty dict.

IMO, it's more likely to want an error here, especially for the intended use case of reading stage params into user code. I would much rather break early with a helpful error message than have to debug that params_show() returned an empty dict.

@dberenbaum
Copy link
Contributor Author

A warning might be reasonable also, so at least it's not silently returning the empty dict?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A: api Related to the dvc.api p2-medium Medium priority, should be done, but less important ui user interface / interaction
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants