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

Plugin system: improve error handling #13741

Closed
2 tasks done
jaimergp opened this issue Mar 28, 2024 · 4 comments · Fixed by #13950
Closed
2 tasks done

Plugin system: improve error handling #13741

jaimergp opened this issue Mar 28, 2024 · 4 comments · Fixed by #13950
Labels
plugins pertains to a plugin/subcommand source::contributor created by a frequent contributor tag::ux related to user experience type::feature request for a new feature or capability

Comments

@jaimergp
Copy link
Contributor

Checklist

  • I added a descriptive title
  • I searched open requests and couldn't find a duplicate

What is the idea?

Add a new configuration option for subcommand plugins:

  @conda.plugins.hookimpl
  def conda_subcommands():
      yield conda.plugins.CondaSubcommand(
          name="build",
          summary="Build conda packages from a conda recipe.",
          action=build,
+         base_exception_class=CondaBuildError,
      )

This is then exposed by the plugin manager to conda's exception handling logic to consider them "expected exceptions" instead of unexpected. The kwarg name can also be expected_exception_type and so on.

Why is this needed?

Subcommands plugins will run their code under conda's exception handler. If the exceptions raised are not covered by this logic:

def handle_exception(self, exc_val, exc_tb):
from errno import ENOSPC
from .exceptions import (
CondaError,
CondaMemoryError,
NoSpaceLeftError,
)
if isinstance(exc_val, CondaError):
if exc_val.reportable:
return self.handle_reportable_application_exception(exc_val, exc_tb)
else:
return self.handle_application_exception(exc_val, exc_tb)
if isinstance(exc_val, EnvironmentError):
if getattr(exc_val, "errno", None) == ENOSPC:
return self.handle_application_exception(
NoSpaceLeftError(exc_val), exc_tb
)
if isinstance(exc_val, MemoryError):
return self.handle_application_exception(CondaMemoryError(exc_val), exc_tb)
if isinstance(exc_val, KeyboardInterrupt):
self._print_conda_exception(CondaError("KeyboardInterrupt"), exc_tb)
return 1
if isinstance(exc_val, SystemExit):
return exc_val.code
return self.handle_unexpected_exception(exc_val, exc_tb)

Then conda will create an error report with added verbosity.

This is creating UX issues in conda-build, where it is normal to raise CalledProcessError for a failed build script. See conda/conda-build#5263.

What should happen?

If a subcommand plugin registers an expected exception type, then conda will not create an error report. The full traceback will be available in --debug and -vvv modes, as usual.

Some documentation on how to use this feature should be added too.

Additional Context

Comes from conda/conda-build#5263. For this to benefit conda-build, conda-build will also need to change the types of their expected exceptions.

@jaimergp jaimergp added type::feature request for a new feature or capability plugins pertains to a plugin/subcommand tag::ux related to user experience labels Mar 28, 2024
@jaimergp
Copy link
Contributor Author

An alternative proposed by @jezdez would be to instead have a general "expected_exception_type" plugin hook so any plugin can register their known exception types.

I guess we shouldn't allow generic builtins there, but that can be discussed in the eventual PR.

@travishathaway travishathaway added the source::contributor created by a frequent contributor label Mar 28, 2024
@jaimergp
Copy link
Contributor Author

Another alternative that is floating is that all plugins that wish to have special treatment by the exception handler subclass conda.CondaError. Maybe we just need to document this "requirement" / API.

@jezdez
Copy link
Member

jezdez commented May 7, 2024

Another alternative that is floating is that all plugins that wish to have special treatment by the exception handler subclass conda.CondaError. Maybe we just need to document this "requirement" / API.

That seems like the best course of action TBH.

@jaimergp
Copy link
Contributor Author

Let's document that then. I'll open a PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
plugins pertains to a plugin/subcommand source::contributor created by a frequent contributor tag::ux related to user experience type::feature request for a new feature or capability
Projects
Status: 🏁 Done
Development

Successfully merging a pull request may close this issue.

3 participants