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

Introduce more specific exceptions, like NotFound, AlreadyExists, BadRequest, PermissionDenied, InternalError, and others #376

Merged
merged 8 commits into from
Nov 13, 2023

Commits on Oct 3, 2023

  1. (RFC) Introduce more specific exceptions, like NotFound, `AlreadyEx…

    …ists`, `BadRequest`, `PermissionDenied`, `InternalError`, and others
    
    Improve the ergonomics of SDK, where instead of `except DatabricksError as err: if err.error_code != 'NOT_FOUND': raise err else: do_stuff()` we could do `except NotFound: do_stuff()`. Additionally, it'll make it easier to read stack traces, as they will contain specific exception class name.
    
    # First principles
    - do not override `builtins.NotImplemented` for `NOT_IMPLEMENTED` error code
    - assume that platform error_code/HTTP status code mapping is not perfect and in the state of transition
    - we do represent reasonable subset of error codes as specific exceptions
    
    ## Open questions
    
    ### HTTP Status Codes vs Error Codes
    
    1. Mix between status codes and error codes (preferred)
    2. Rely only on HTTP status codes
    3. Rely only on `error_code`'s
    
    One example is `BAD_REQUEST` error code that maps onto HTTP 400 and to `except BadRequest as err` catch clause. But `MALFORMED_REQUEST`, `INVALID_STATE`, and `UNPARSEABLE_HTTP_ERROR` do also map to HTTP 400. So the proposal is to remap the MALFORMED_REQUEST to `BadRequest` exception.
    
    Another corner-case is UC:
    - 'METASTORE_DOES_NOT_EXIST': NotFound,
    - 'DAC_DOES_NOT_EXIST': NotFound,
    - 'CATALOG_DOES_NOT_EXIST': NotFound,
    - 'SCHEMA_DOES_NOT_EXIST': NotFound,
    - 'TABLE_DOES_NOT_EXIST': NotFound,
    - 'SHARE_DOES_NOT_EXIST': NotFound,
    - 'RECIPIENT_DOES_NOT_EXIST': NotFound,
    - 'STORAGE_CREDENTIAL_DOES_NOT_EXIST': NotFound,
    - 'EXTERNAL_LOCATION_DOES_NOT_EXIST': NotFound,
    - 'PRINCIPAL_DOES_NOT_EXIST': NotFound,
    - 'PROVIDER_DOES_NOT_EXIST': NotFound,
    
    ### Naming conflict resolution
    
    We have three sources of naming:
    - `error_code`
    - HTTP Status
    - Python builtin exceptions
    
    We still have to define which name takes the precedence.
    nfx committed Oct 3, 2023
    Configuration menu
    Copy the full SHA
    244de7c View commit details
    Browse the repository at this point in the history

Commits on Oct 10, 2023

  1. Configuration menu
    Copy the full SHA
    0fb81ee View commit details
    Browse the repository at this point in the history
  2. now with tests

    nfx committed Oct 10, 2023
    Configuration menu
    Copy the full SHA
    80b728d View commit details
    Browse the repository at this point in the history
  3. ..

    nfx committed Oct 10, 2023
    Configuration menu
    Copy the full SHA
    0021809 View commit details
    Browse the repository at this point in the history
  4. Added UNKNOWN and DATA_LOSS

    nfx committed Oct 10, 2023
    Configuration menu
    Copy the full SHA
    ea598cc View commit details
    Browse the repository at this point in the history

Commits on Nov 10, 2023

  1. generate exceptions

    nfx committed Nov 10, 2023
    Configuration menu
    Copy the full SHA
    52ff2ea View commit details
    Browse the repository at this point in the history
  2. ..

    nfx committed Nov 10, 2023
    Configuration menu
    Copy the full SHA
    47bd23e View commit details
    Browse the repository at this point in the history

Commits on Nov 13, 2023

  1. remove unnecessary __all__

    mgyucht committed Nov 13, 2023
    Configuration menu
    Copy the full SHA
    7294c0d View commit details
    Browse the repository at this point in the history