Skip to content

Conversation

@psyclaudeZ
Copy link
Contributor

@psyclaudeZ psyclaudeZ commented Oct 20, 2025

Before this PR

Addressing #910.

After this PR

A few things happening:

  1. Threading through a CLI option for generating the errors.
  2. Core generation logic.
  3. Used Claude Code to generate the tests for me.

The resulting error look like:

class product_DatasetNotFound(ConjureHTTPError):
    """Thrown when the requested dataset does not exist
    """

    ERROR_CODE = "NOT_FOUND"
    ERROR_NAMESPACE = "Datasets"
    ERROR_NAME = "DatasetNotFound"

    class SafeArgs(TypedDict):
        dataset_rid: str
        available_datasets: List[str]

    def __init__(self, base_error: ConjureHTTPError) -> None:
        super().__init__(
            status_code=base_error.status_code,
            error_code=base_error.error_code,
            error_name=base_error.error_name,
            error_instance_id=base_error.error_instance_id,
            parameters=base_error.parameters
        )
        self.safe_args: product_DatasetNotFound.SafeArgs = {
            'dataset_rid': base_error.parameters['datasetRid'],
            'available_datasets': base_error.parameters['availableDatasets']
        }

    @classmethod
    def is_instance(cls, error: ConjureHTTPError) -> bool:
        return (
            error.error_name == cls.ERROR_NAME and
            error.error_code == cls.ERROR_CODE
        )

    @classmethod
    def from_error(cls, error: ConjureHTTPError) -> 'product_DatasetNotFound':
        if not cls.is_instance(error):
            raise ValueError(f"Error is not a {cls.ERROR_NAME}")
        return cls(error)


product_DatasetNotFound.__name__ = "DatasetNotFound"
product_DatasetNotFound.__qualname__ = "DatasetNotFound"
product_DatasetNotFound.__module__ = "package_name.product"

Also placed a follow-up item for using the enum for ErrorCode after palantir/conjure-python-client#171.

==COMMIT_MSG==
Add an option to generate exceptions for Conjure errors
==COMMIT_MSG==

Possible downsides?

@changelog-app
Copy link

changelog-app bot commented Oct 20, 2025

Successfully generated changelog entry!

What happened?

Your changelog entries have been stored in the database as part of our migration to ChangelogV3.

Entry generated via PR title

To modify this entry, edit PR title using proper format.


📋Changelog Preview

✨ Features

  • Add an option to generate exceptions for Conjure errors (#1157)

@psyclaudeZ psyclaudeZ requested a review from johnhany97 October 20, 2025 23:33
@psyclaudeZ psyclaudeZ marked this pull request as ready for review October 20, 2025 23:33
@psyclaudeZ psyclaudeZ requested a review from dtobin October 23, 2025 21:11
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.

2 participants