Skip to content

Shortcircuit command call on error - #49438

Merged
bugraoz93 merged 3 commits into
apache:mainfrom
aritra24:check_login
Apr 23, 2025
Merged

bugraoz93 merged 3 commits into
apache:mainfrom
aritra24:check_login

Conversation

@aritra24

Copy link
Copy Markdown
Collaborator

closes: #49139


^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named {pr_number}.significant.rst or {issue_number}.significant.rst, in airflow-core/newsfragments.

@aritra24

Copy link
Copy Markdown
Collaborator Author

@bugraoz93 what are your thoughts? I felt this was the most minimal way of shorting the command call. If the credential check fails it exits early with the error

 $airflowctl providers list
Failed to run due to  No credentials found in /root/.config/airflow

@bugraoz93

Copy link
Copy Markdown
Contributor

@bugraoz93 what are your thoughts? I felt this was the most minimal way of shorting the command call. If the credential check fails it exits early with the error

 $airflowctl providers list
Failed to run due to  No credentials found in /root/.config/airflow

@aritra24 I first did this too, but printing an error to the user on api package is undesirable.
How about adding a try catch here as a more generic call where we can manage multiple types of exceptions coming from packages that shouldn't print to the user but raise the exception, then we can catch a generic exception coming from decordator or something more broad than exceptions in commands for any method? This could be a more centric approach and prevent printing much on

cli_parser.py

def safe_call_action_command(function: Callable, args:Iterable[Arg]) -> None:
    try:
        function(args)
    except AirflowCtlNotFoundException as e:
        rich.print(f"Error: {e}")

__main__.py

from airflowctl.ctl.cli_parser import safe_call_action_command


def main():
    parser = cli_parser.get_parser()
    argcomplete.autocomplete(parser)
    args = parser.parse_args()
    safe_call_action_command(args.func, args=args)

def main():
parser = cli_parser.get_parser()
argcomplete.autocomplete(parser)
args = parser.parse_args()
args.func(args)

@bugraoz93 bugraoz93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The next step should be throw specific exception class indicating only credentials not fiund and gove specific error message from ctl package. Thanks for the changes!

@aritra24

Copy link
Copy Markdown
Collaborator Author

@bugraoz93 do we wanna do it as part of this pr? Or as a follow up?

@bugraoz93

Copy link
Copy Markdown
Contributor

@bugraoz93 do we wanna do it as part of this pr? Or as a follow up?

If you can do it in this that would be great! Because then we can use more granular exceptions. Let me put request change to prevent merge

@bugraoz93 bugraoz93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Just put to make granular exception and giving message in safe call

@aritra24

Copy link
Copy Markdown
Collaborator Author

Ack, sounds good! Will do

@aritra24

Copy link
Copy Markdown
Collaborator Author

@bugraoz93 is this kind of what you were talking about wrt your last comment? Adding a more granular sub exception?

@bugraoz93 bugraoz93 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the changes and for addressing the comment! We should drive AirflowCtlFileNotFoundException while working with files in commands such as connections, variables or pools. Then we can easily identify them and map proper errors.

@aritra24

Copy link
Copy Markdown
Collaborator Author

@bugraoz93 / @potiuk if this is ready we can merge this in?

@bugraoz93
bugraoz93 merged commit cf831e5 into apache:main Apr 23, 2025
@aritra24
aritra24 deleted the check_login branch April 23, 2025 17:46
prabhusneha pushed a commit to astronomer/airflow that referenced this pull request Apr 25, 2025
* Moved error check up to ctl level

* More granular exceptions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AIP-81 Handle Empty Credentials

2 participants