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

add: meaningful message upon adding overlapping paths #3296

Merged
merged 1 commit into from
Feb 13, 2020

Conversation

pared
Copy link
Contributor

@pared pared commented Feb 10, 2020

  • ❗ Have you followed the guidelines in the Contributing to DVC list?

  • πŸ“– Check this box if this PR does not require documentation updates, or if it does and you have created a separate PR in dvc.org with such updates (or at least opened an issue about it in that repo). Please link below to your PR (or issue) in the dvc.org repo.

  • ❌ Have you checked DeepSource, CodeClimate, and other sanity checks below? We consider their findings recommendatory and don't expect everything to be addressed. Please review them carefully and fix those that actually improve code or fix bugs.

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™

Fixes #3218

@pared
Copy link
Contributor Author

pared commented Feb 10, 2020

Before:
asciicast

After:
asciicast

Comment on lines 333 to 343
class AddOverlappingPathsError(DvcException):
def __init__(self, parent, overlapping_out):
super().__init__(
"Cannot add '{out}', because it is overlapping with other DVC "
"tracked output: '{parent}'.\nTo include '{out}' in '{parent}', "
"run 'dvc commit {parent_stage}'".format(
out=overlapping_out,
parent=parent,
parent_stage=parent.stage.relpath,
)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's do it a bit differently. Let's only keep OverlappingOutputPathsError, but raise it with specific message instead of hardcoding it into the exception class itself. That way we won't spawn new entities and it will be nicely catchable from outside if needed πŸ™‚

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, makes sense

dvc/repo/add.py Outdated
except OverlappingOutputPathsError as e:
msg = (
"Cannot add '{out}', because it is overlapping with other "
"DVC tracked output: '{parent}'.\nTo include '{out}' in "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to move a line down if you have \n. E.g.

"Cannot add '{out}', because it is overlapping with other "
"DVC tracked output: '{parent}'.\n"
"To include '{out}' in ..."

much easier to comprehend that way. Or was it black who did that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nah, black gets in the way only when lines do not match, I probably did that to save some lines :P

dvc/repo/add.py Outdated
repo.check_modified_graph(stages)
try:
repo.check_modified_graph(stages)
except OverlappingOutputPathsError as e:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
except OverlappingOutputPathsError as e:
except OverlappingOutputPathsError as exc:

DS and others complain about such naming.

dvc.add(os.path.join("dir", "file2"))
assert str(e.value) == (
"Cannot add 'dir/file2', because it is overlapping with other DVC "
"tracked output: 'dir'.\nTo include 'dir/file2' in 'dir', run "
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please create a new line after \n here.

@efiop
Copy link
Contributor

efiop commented Feb 11, 2020

@pared Also check the tests, please.

@pared pared force-pushed the 3218_add_in_dir branch 2 times, most recently from 9a1d0fa to 3adcbd2 Compare February 11, 2020 18:00
Comment on lines 338 to 339
"Paths for outs:\n'{}'('{}')\n'{}'('{}')\noverlap."
" To avoid unpredictable behaviour, "
Copy link
Contributor

@efiop efiop Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Please use consistent formatting. You skip trailing space in the first line but add it in the second one. IIRC prefered way to have a trailing space rather than a leading space. CC @jorgeorpinel

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree about consistency. Idk what's preferred though, I used to put trailing space last but later I noticed most of you use trailing first so rn there's a mix throughout docs. Maybe trailing space first is best because it makes it extra obvious that it's a continuation string? Up to you, I just rec to be consistent (available to review all existing strings once you decide, please lmk).

@pared pared requested a review from efiop February 11, 2020 18:35
@efiop efiop merged commit ccca126 into iterative:master Feb 13, 2020
@shcheklein
Copy link
Member

minor: we use sometimes outs sometimes outputs/output in this PR - would be probably good to use one of those consistently (probably output/outputs to avoid slang-slang)

@pared pared deleted the 3218_add_in_dir branch March 24, 2020 09:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

dvc add a file from data directory
4 participants