microsoft / knack

Knack - A Python command line interface framework
https://pypi.python.org/pypi/knack
MIT License
347 stars 95 forks source link

Use try-finally to ensure `filter_output` is unregistered #278

Open ReaNAiveD opened 1 year ago

ReaNAiveD commented 1 year ago

Related Issue https://github.com/Azure/azure-cli/issues/27228

Description If query_expression.search raises an Exception, the following line cli_ctx.unregister_event(EVENT_INVOKER_FILTER_RESULT, filter_output) won't be executed, and the callback with error remains in the _event_handlers. image Az Interactive uses the same cli_ctx for every command execution, so if there is an exception related to --query, it will keep happening for any subsequent commands. image