GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Move some exception translation logic to BaseServiceException · Issue #413 · googleapis/google-cloud-java

Move some exception translation logic to BaseServiceException #413

New issue
Copy link
New issue
Copy link
Closed
Closed
Move some exception translation logic to BaseServiceException#413
Copy link
Assignees
mziccard
Labels
🚨 criticalP0 critical issue. Requires immediate fixapi: coretriage meI really want to be triaged.

Description

@mziccard
mziccard
opened on Nov 24, 2015
Issue body actions

In DefaultStorageRpc (and also other services as DefaultBigQueryRpc) we have code handling the translation of IOException to service specific exceptions:

private static BigQueryException translate(IOException exception) {
  BigQueryException translated;
  if (exception instanceof GoogleJsonResponseException
      && ((GoogleJsonResponseException) exception).getDetails() != null) {
    translated = translate(((GoogleJsonResponseException) exception).getDetails());
  } else {
    translated =
        new BigQueryException(BigQueryException.UNKNOWN_CODE, exception.getMessage(), false);
  }
  translated.initCause(exception);
  return translated;
}

private static BigQueryException translate(GoogleJsonError exception) {
  boolean retryable = RETRYABLE_CODES.contains(exception.getCode());
  return new BigQueryException(exception.getCode(), exception.getMessage(), retryable);
}

Part of this logic should be moved to BaseServiceException

Activity

  1. mziccard
    added
    api: core
    on Nov 24, 2015
  2. aozarov commented on Nov 24, 2015

    @aozarov
    aozarov
    on Nov 24, 2015
    Contributor
    More actions

    When we do so, we should probably also add a boolean parameter to indicate if the failed operation is idempotent. The retryable property should be true only if operation is idempotent (passed by the caller to translate) and error code (could be derived from a set passed in the constructor or subclasses) is retryable.

    An example of a non-idempotent operation could be pubsub publish as messages do not include id and a retry can cause the same message to be published more than once (though one can argue that because
    pub-sub is a "at-least-once message delivery" system that should not matter, so maybe this is not a great example).

  3. mziccard commented on Dec 1, 2015

    @mziccard
    mziccard
    on Dec 1, 2015
    ContributorAuthor
    More actions

    In DefaultStorageRpc to say if an exception is retryable we check whether exception's error code is in RETRYABLE_CODES, but we also check whether the error message is "InternalError":

    private static StorageException translate(GoogleJsonError exception) {
      boolean retryable = RETRYABLE_CODES.contains(exception.getCode())
          || "InternalError".equals(exception.getMessage());
      return new StorageException(exception.getCode(), exception.getMessage(), retryable);
    }

    Looking here that error message should be only associated to 500 errors. Is there a reason I am missing for checking it?

  4. aozarov commented on Dec 1, 2015

    @aozarov
    aozarov
    on Dec 1, 2015
    Contributor
    More actions

    see "InternalError" associated with a 403.

  5. mziccard commented on Dec 1, 2015

    @mziccard
    mziccard
    on Dec 1, 2015
    ContributorAuthor
    More actions

    Oops, sorry I missed that. This 'peculiar' behavior of each service makes hard to move all translation logic to ServiceException (e.g. testing if error code is in a set of retryable codes is not enough for storage as we also need to check the message). Checking for "InternalError" message for services as BigQuery would do no harm but I'm not sure moving such code to ServiceException is the best choice.

  6. aozarov commented on Dec 1, 2015

    @aozarov
    aozarov
    on Dec 1, 2015
    Contributor
    More actions

    There are various ways this could be handled. One option is to make an abstract isRetryable method that accepts a GoogleJsonError. most base service specific implementation would just have

    @Override
    protected boolean isRetryable(GoogleJsonError exception) {
      return RETRYABLE_CODES.contains(exception.getCode());
    }

    where as StorageException would override it as

    @Override
    protected boolean isRetryable(GoogleJsonError exception) {
      return RETRYABLE_CODES.contains(exception.getCode()) || "InternalError".equals(exception.getMessage());
    }

    If you were thinking to somehow provide the set of error codes (e.g. by overriding a method retryableErrorCodes) then you can also make the common implementation for isRetryable
    overridable and StorageExcetpion will override it and inside return

    return super.isRetryable(exception) || "InternalError".equals(exception.getMessage());
  7. aozarov commented on Dec 16, 2015

    @aozarov
    aozarov
    on Dec 16, 2015
    Contributor
    More actions

    As part of this change we could simply (and maybe use a common) the service's EXCEPTION_HANDLER_INTERCEPTOR Interceptor.

  8. mziccard commented on Apr 4, 2016

    @mziccard
    mziccard
    on Apr 4, 2016
    ContributorAuthor
    More actions

    This was fixed in #554

  9. mziccard
    closed this as completedon Apr 4, 2016
  10. yoshi-automation
    added
    triage meI really want to be triaged.
    🚨 criticalP0 critical issue. Requires immediate fix
    on Apr 6, 2020
  11. JustinBeckwith
    assigned
    mziccard
    on Feb 1, 2021
  12. github-actions
    added a commit that references this issue on Jun 21, 2022

    build(deps): update dependency com.google.cloud:google-cloud-shared-c…

    819673b
  13. github-actions
    added 2 commits that reference this issue on Jun 29, 2022

    chore: regenerate README (googleapis#413)

    6dde130

    build(deps): update dependency com.google.cloud:google-cloud-shared-c…

    a816a73
  14. github-actions
    added a commit that references this issue on Aug 18, 2022

    build(deps): update dependency org.apache.maven.plugins:maven-project…

    5f660d9
  15. github-actions
    added a commit that references this issue on Oct 5, 2022

    chore(main): release 1.2.5 (googleapis#413)

    9af8ebb
  16. suztomo
    added 2 commits that reference this issue on Feb 1, 2023

    chore(main): release 2.0.0 (#739)

    ea9f421

    deps: update dependency io.grpc:grpc-protobuf to v1.49.0 (#413)

    8328c10
  17. meltsufin
    added a commit that references this issue on Dec 22, 2025

    chore: Re-generated to pick up changes from synthtool. (#413)

    f07b1da
  18. chingor13
    added a commit that references this issue on Jan 6, 2026

    chore: add changelog to cloud-rad (#413)

    f6cc15e
  19. chingor13
    added a commit that references this issue on Jan 22, 2026

    chore: adding cloud-rad java xrefs (#413)

    0e4ac4b
  20. chingor13
    added a commit that references this issue on Feb 24, 2026

    chore(deps): update dependency org.apache.maven.plugins:maven-depende…

    fb8a8ff
  21. suztomo
    added a commit that references this issue on Mar 11, 2026

    chore: Re-generated to pick up changes from synthtool. (googleapis#413)

    37e9f23
  22. chingor13
    added a commit that references this issue on Mar 12, 2026

    chore(deps): update dependency org.apache.maven.plugins:maven-depende…

    5e01618
  23. suztomo
    added a commit that references this issue on Mar 23, 2026

    chore: marks the branch 1.21.x as stable (googleapis#413)

    1e7a436
  24. meltsufin
    added 2 commits that reference this issue on Apr 29, 2026

    chore(java): enable generated-files-bot (#413)

    f4565f9

    chore(java): enable generated-files-bot (#413)

    e5ff28a
  25. benjaminp
    added a commit that references this issue on Jul 13, 2026

    chore: update CODEOWNERS (googleapis#413)

    7228fa2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @mziccard
    mziccard

Labels

🚨 criticalP0 critical issue. Requires immediate fixapi: coretriage meI really want to be triaged.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.