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

ADR: Custom Exceptions Patterns #186

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anastasds
Copy link
Contributor

No description provided.

@anastasds anastasds changed the title Custom Exceptions Patterns ADR: Custom Exceptions Patterns Jan 29, 2025
Copy link
Contributor

@jwm4 jwm4 left a comment

Choose a reason for hiding this comment

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

This seems like a sensible idea.


The historically pervasive pattern for exception handling during application runtime is to catch internally raised exceptions in the CLI layer and use `click.secho` followed by `click.exceptions.Exit` to display a useful error message to the user before exiting the application. This leaves a risk of intermediate calls between the site of the exception and the user-facing layer changing, leading to missed new exceptions and outdated caught exceptions. A second issue is that of discoverability and verification: given a `click.exceptions.Exit` exception handling, it is not clear from the code where the caught exception originates from in the call stack, and, similarly, given a piece of code that can raise an exception, it is not clear from the local code whether that exception is properly handled in the CLI layer without investigation.

These issues will compound whenever REST APIs begin development.
Copy link
Contributor

Choose a reason for hiding this comment

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

and/or whenever the SDK APIs begin development.

docs/adr-custom-exceptions.md Outdated Show resolved Hide resolved
Copy link
Member

@nathan-weinberg nathan-weinberg left a comment

Choose a reason for hiding this comment

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

Generally I agree with this, worth calling out that some of this work is ongoing in the Core repo as part of instructlab/instructlab#2325

docs/adr-custom-exceptions.md Outdated Show resolved Hide resolved
Signed-off-by: Anastas Stoyanovsky <[email protected]>
* CLI layer error handling will be easy to understand and trace.
* Whenever REST APIs are developed, HTTP error codes should be easier to be associated with specific exceptions.
* It should be easier to compose useful error messages for the user.
* It should be easier to correctly scope exception handling (consider a `URLError` raised about SSL verification, for example, versus a custom `SSlVerificationException`).
Copy link

Choose a reason for hiding this comment

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

I'm with you in general but not for this specific example (as I expressed in the patch), for the reason that we cannot and should not enumerate all the possible ways a request may fail, so letting URLError bubble up is fine here. (Caught further up the call stack and transformed into ilab specific exception as needed.)

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