feat: Add common exceptions and map_exception helper#42
Merged
Conversation
This was referenced Jun 13, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
@geospatial-jeff
Users writing generic code with obspec may wish to catch common exceptions. For example,
a user might wish to perform a head request but allow for the case where the object does
not exist.
Common exceptions pose a challenge for obspec. In general obspec strives to use
structural subtyping (protocols) rather than nominal subtyping
(subclassing). This is because protocols allow for implementations to
have no knowledge of or dependency on a shared base library (obspec) while still being
able to use the same interface.
However, structural subtyping does not work for exceptions: when you use
except Exception, that uses anisinstancecheck under the hood.As a workaround, we define well-known names for exceptions and expect external
implementations to use the same names.
Obspec users
Use the [
map_exception][obspec.exceptions.map_exception] function in this module toconvert from an implementation-defined exception to an obspec-defined exception.
!!! note
If you don't care about catching exceptions, you can ignore this module entirely.
Obspec implementors
Create your own exceptions but ensure you use the same names for your own exceptions
as defined in this module.
You may also have other exceptions that are not defined here, but any exceptions that
logically fall under the purview of the exceptions defined here should your exceptions
with the same name.