Skip to content

Conversation

@fabiosantoscode
Copy link
Contributor

This tries to clear up the error message of NoRemoteError in case the user doesn't have any remotes, and provides instructions on how to create a remote, or a default remote. It also clears the extra newline at the end.

Fixes #3121


  • ❗ 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. 🙏

return self._init_remote(remote)

raise NoRemoteError(command)
has_any_remote = any(key.startswith("remote ") for key in self._config)
Copy link
Contributor

Choose a reason for hiding this comment

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

This feels as a part of the logic inside exception itself. So everything should be either inside or outside.

Also, key.startswith("remote ") is a bit fishy, we check for regex in other places.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it, changed that to use list_options as I've found elsewhere. Remote URLs are required so finding any means that there's a valid remote that could be used.

dvc/config.py Outdated
"or use:\n"
" dvc {} -r <name>\n".format(command)
)
def __init__(self, command, *, config=None):
Copy link
Contributor

@pared pared Jan 23, 2020

Choose a reason for hiding this comment

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

what is * for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to make sure config can only be used as a keyword argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reasoning for it is to prevent the exception from being initialized with some context that might not be a Config.

Copy link
Contributor

Choose a reason for hiding this comment

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

So it is to make sure that we will never use it as a keyword argument? Isn't it kind of protecting the code from the developer?

Copy link
Contributor Author

@fabiosantoscode fabiosantoscode Jan 23, 2020

Choose a reason for hiding this comment

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

Exactly.

Edit: No, actually it's to make sure we always use it as a keyword argument.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nothing makes it special really. I just thought somebody might make a mistake and pass something else as an argument here. But I'll change it back.

Copy link
Contributor

Choose a reason for hiding this comment

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

@fabiosantoscode this is a good point, and we actually have seen few times when wrong arguments are passed due to ordering, but I guess that there is no point in introducing that in this single place if we do differently everywhere else. We just need to be careful when using kwargs as args.

Copy link
Contributor

Choose a reason for hiding this comment

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

I am +1 on using keyword only args in situations like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

@Suor So maybe we should enforce this rule throughout the code?

Copy link
Contributor

Choose a reason for hiding this comment

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

@pared @Suor I think we have a ticket for doing that in api.py already. Just need to be consistent, we weren't doing that earlier because py2 didn't support it, IIRC.

@Suor
Copy link
Contributor

Suor commented Jan 24, 2020

Approved it.

A general consideration regarding messages like this - we've discussed adding more or less uniform HINTs in such situations, which will take into account context better, e.g. remote(s) name, having several remotes, command/options/api call. How this should be implemented and how far should we go is still TBD in #2559.

@Suor
Copy link
Contributor

Suor commented Jan 24, 2020

Thx, @fabiosantoscode.

dvc/config.py Outdated
Comment on lines 28 to 49
has_any_remote = False
if config:
has_any_remote = bool(
config.list_options(
Config.SECTION_REMOTE_REGEX, Config.SECTION_REMOTE_URL
)
)

if has_any_remote:
msg = (
"no remote specified. Setup default remote with\n"
" dvc remote default <remote name>\n"
"or use:\n"
" dvc {} -r <remote name>".format(command)
)
else:
msg = (
"no remote specified. Create a remote with\n"
" dvc remote add <remote name> <remote url>\n"
"To create a default remote use the -d flag:\n"
" dvc remote add -d <remote name> <remote url>"
)
Copy link
Contributor

@efiop efiop Jan 24, 2020

Choose a reason for hiding this comment

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

Having such a complex logic in the exception is self is rather odd. How about we process config in the code itself and then raise NoRemoteError with the pre-crafted message?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Works for me. The message was being generated in __init__ so I kept it there.

dvc/config.py Outdated
Comment on lines 45 to 46
"no remote specified. Create a remote with\n"
" dvc remote add <remote name> <remote url>\n"
Copy link
Contributor

Choose a reason for hiding this comment

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

This part is no relevan without -d, because if someone would've provided the remove, we would go if remote branch of execution (see below where you raise). So the hint here should assume -d.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right!

@fabiosantoscode
Copy link
Contributor Author

@efiop I've tried to address your comments with a new commit. I've removed the dvc remote add without the -d and moved the message formatting out of the exception class.

Copy link
Contributor

@efiop efiop left a comment

Choose a reason for hiding this comment

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

Thanks @fabiosantoscode !

@efiop efiop merged commit 4d5faab into iterative:master Jan 24, 2020
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.

push: improve 'no remote specified hint

4 participants