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

provide better error message outside of a kedro project #3680

Merged
merged 11 commits into from
Mar 6, 2024

Conversation

noklam
Copy link
Contributor

@noklam noklam commented Mar 4, 2024

Description

Close #1829
To detect whether it is out of a kedro project is out of scope, it should be fixed in #1831

better-error-message

Development notes

  • catch_exception = "click.exceptions.UsageError: No such command" Note click's app by default convert all ExceptionHandles to error message. It's not possible to intercept the error class unless we implement Consider using run(standalone_mode=True) to fix packaged Kedro project getting a sys.exit  #2682. The current workaround is catching the traceback which works reasonable well.
  • I have considered to provide the exact command in the message, but it overcomplicates the problem. See screenshot below:

sub command:
image

sub group command:
image

click propagate subcommand by forwarding the argument. Ideally in the 2nd screenshot, we want to see No such command 'random command', but this is not possible. This is how click always behave and consistent with existing Kedro CLI. The solution is that the error message will always mention runorjupyter` instead of showing the actual command user runs, I think this is clear enough and is an improvement.

I've also added a hint in the error message:

Hint: Kedro is looking for a file called 'pyproject.toml, is one present in your current working directory?

Technically Kedro is searching for a pyproject.toml which has tool.kedro(sometimes we see projects with multiple pyproject.toml, some are kedro project some are not). I try to keep the hint simple and thus ignoring the details.

Developer Certificate of Origin

We need all contributions to comply with the Developer Certificate of Origin (DCO). All commits must be signed off by including a Signed-off-by line in the commit message. See our wiki for guidance.

If your PR is blocked due to unsigned commits, then you must follow the instructions under "Rebase the branch" on the GitHub Checks page for your PR. This will retroactively add the sign-off to all unsigned commits and allow the DCO check to pass.

Checklist

  • Read the contributing guidelines
  • Signed off each commit with a Developer Certificate of Origin (DCO)
  • Opened this PR as a 'Draft Pull Request' if it is work-in-progress
  • Updated the documentation to reflect the code changes
  • Added a description of this change in the RELEASE.md file
  • Added tests to cover my changes
  • Checked if this change will affect Kedro-Viz, and if so, communicated that with the Viz team

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
…_commands

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Mar 4, 2024

(kedro) Nok_Lam_Chan@ kedro % kedro -V
kedro, version 0.19.3

You are not in a Kedro project! Project specific commands such as 'run' or 'jupyter' are only available within a project directory.

The e2e test is catching an error that the error message show up in kedro -V, which shouldn't be the case.

@noklam
Copy link
Contributor Author

noklam commented Mar 4, 2024

It appears that kedro using standalone=True (click default), which always issue SystemExit instead of the actual exception.

https://click.palletsprojects.com/en/7.x/exceptions/

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam
Copy link
Contributor Author

noklam commented Mar 4, 2024

#2682 I am more convinced this is something that we should do.

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
@noklam noklam marked this pull request as ready for review March 5, 2024 13:46
Comment on lines +4 to +6
# The constant need to be defined first otherwise it causes circular depdencies
ORANGE = (255, 175, 0)
BRIGHT_BLACK = (128, 128, 128)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can these go in kedro.utils? So you wouldn't have to define them first.

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 can, but I think cli is the correct scope as this only affect CLI color. Alternative is keep it in cli/cli.py because this is the only file that get used at the moment.

@datajoely
Copy link
Contributor

Amazing!

Copy link
Contributor

@ankatiyar ankatiyar left a comment

Choose a reason for hiding this comment

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

Tested this and it works well! Right now it shows this error message if you are either outside a kedro project or in a subdirectory but I also tested this in conjunction with the changes in #3683 and it works as expected. Thanks @noklam!

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Copy link
Member

@merelcht merelcht left a comment

Choose a reason for hiding this comment

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

Tested and looks all good to me 👍

@noklam noklam merged commit da709d4 into main Mar 6, 2024
34 checks passed
@noklam noklam deleted the noklam/provide-better-error-message-1829 branch March 6, 2024 18:08
merelcht pushed a commit that referenced this pull request Mar 7, 2024
* provide error message outside of kedro project with rich style

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* change to add custom click message on error instead of overriding get_commands

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* add test

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* clean up

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* catch the error message from click

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* fix unitests

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* Update error message

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* move color constant to the upper module

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* fix imports

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>

* release note

Signed-off-by: Nok <nok.lam.chan@quantumblack.com>

---------

Signed-off-by: Nok Lam Chan <nok.lam.chan@quantumblack.com>
Signed-off-by: Nok <nok.lam.chan@quantumblack.com>
Signed-off-by: Merel Theisen <merel.theisen@quantumblack.com>
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.

Provide better error message when you try to use a project command from outside a project
4 participants