palantir / palantir/conjure-python
Generate python exceptions for conjure errors
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 27
- Forks
- 19
- Avg merge
- 12h 22m
- Merged PRs (30d)
- 15
Description
When using conjure generated clients, any error is represented by a generic ConjureHTTPException that requires manual parsing to determine exactly what the error is. If I have some conjure error
SomeException:
docs: Something went wrong
code: INVALID_ARGUMENT
namespace: MyService
safe-args:
argument: string
object: SomeObjectWithFields
unsafe-args:
unsafeArgument: string
I would like to get some generated python exception
class SomeException(Exception):
"""
Something went wrong
"""
NAMESPACE = "MyService"
ERROR_CODE = "INVALID_ARGUMENT" # probably want this to be an enum
ERROR_NAME = "MyService:SomeException"
def __init__(self, conjure_exception: ConjureHTTPError):
# do some validation
self.unsafe_args = ...
self.safe_args = ...
@staticmethod
def is_instance(self, conjure_exception: ConjureHTTPError) -> bool:
# check if the conjure exception is this
return conjure_exception.error_name == SomeException.ERROR_NAME
That way I can use this in my code to convert a ConjureHTTPError into a more user friendly exception, with some actual types
try:
return some_service.endpoint()
except ConjureHTTPError as err:
if SomeException.is_error(err):
actual_exception = SomeException(err)
raise UserFriendlyError(actual_exception.safe_args.argument, actual_exception.object.some_object_field)
# maybe check some other exceptions here too
raise err
Both java and typescript conjure clients do this, I think it would be really useful to have it in python as well
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing how the Java and TypeScript Conjure clients generate typed exceptions, then locate the Python generator entry point for client error handling. Define the generated exception metadata, safe and unsafe argument types, and matching behavior, and verify that generated clients expose typed exceptions instead of only ConjureHTTPException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100