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

Exit with exit code 1 when there's an exception #4122

Merged
merged 7 commits into from
Sep 3, 2024
Merged

Exit with exit code 1 when there's an exception #4122

merged 7 commits into from
Sep 3, 2024

Conversation

ankatiyar
Copy link
Contributor

@ankatiyar ankatiyar commented Aug 28, 2024

Description

Small regression from #4075

Development notes

Reminder to self: Will have to revert kedro-org/kedro-plugins#813 after the next release

Note to reviewers:
Please verify if #4073 is still resolved!

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: Ankita Katiyar <ankitakatiyar2401@gmail.com>
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
@ankatiyar ankatiyar changed the title Exit with exit code when there's an exception Exit with exit code 1 when there's an exception Aug 29, 2024
@ankatiyar ankatiyar marked this pull request as ready for review August 29, 2024 11:55
@lrcouto
Copy link
Contributor

lrcouto commented Aug 29, 2024

Was the program not returning an 1 already in the case of failure? It should be failing both unit and e2e tests if it wasn't.

@ankatiyar
Copy link
Contributor Author

Was the program not returning an 1 already in the case of failure? It should be failing both unit and e2e tests if it wasn't.

The kedro-docker tests were failing because of this kedro-org/kedro-plugins#800. I think this branch of logic is executed when the exceptions come from outside like the kedro project itself, which I don't know if we test for.

@@ -210,7 +210,8 @@ def main(
project_metadata=self._metadata, command_args=args, exit_code=1
)
hook_called = True
raise
traceback.print_exc()
sys.exit(1)
Copy link
Contributor

@ElenaKhaustova ElenaKhaustova Aug 30, 2024

Choose a reason for hiding this comment

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

Now it looks like we don't need hook_called flag anymore as all the branches that set it to true now have sys.exit(). So maybe we can just move self._cli_hook_manager.hook.after_command_run to the try block and get rid of finally, so the logic is a bit cleaner?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't want to block the PR, so we can pay attention to this in a separate one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, I think you're right we don't need the finally block at all. If the the command executes successfully or the command doesn't exist - it goes into the first except block otherwise if there's an exception it is caught by the next except. Hook gets called either way.

Copy link
Contributor

Choose a reason for hiding this comment

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

Check if it doesn't get called twice on a successful case too, it's why that finally block was introduced.

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 the behaviour is as expected and still solves #4073

Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
@ElenaKhaustova
Copy link
Contributor

Tested the changes, the #4075 is still solved but the traceback view changed:

Before changes:
Screenshot 2024-08-30 at 17 34 43

After changes:
Screenshot 2024-08-30 at 17 34 31

@ankatiyar ankatiyar marked this pull request as draft September 2, 2024 09:54
Signed-off-by: Ankita Katiyar <ankitakatiyar2401@gmail.com>
@ankatiyar
Copy link
Contributor Author

Did a little more investigation - the problem just turned out to be the indentation of sys.exit(), it was inside the if block so KedroCliError was exiting with 0.

When there's a CLI error such as was the case with docker e2e test - kedro-org/kedro-plugins#800 it goes into the first except SystemExit block and when there's any other kind of exceptions it should go into the except Exception block. In either cases we now have after_command_hook called so we don't need the finally block.

Please take another look @ElenaKhaustova @merelcht @lrcouto

@ankatiyar ankatiyar marked this pull request as ready for review September 2, 2024 15:02
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.

Tried the revised implementation, and looks all good 👍

Copy link
Contributor

@ElenaKhaustova ElenaKhaustova left a comment

Choose a reason for hiding this comment

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

Thank you, @ankatiyar!

Tested the updates - all works as expected 🚀

@ankatiyar ankatiyar merged commit a10690a into main Sep 3, 2024
34 checks passed
@ankatiyar ankatiyar deleted the exit-codes branch September 3, 2024 08:58
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.

4 participants