Skip to content

HttpError error_details isn't populated unless __repr__ is called first #1255

Closed

Description

@jceresini

I was trying to handle an HttpError by looking at the contents of the error_details attribute. I noticed the attribute is a null-string unless I trigger the __repr__ function first. For example, this does not work as the error_details is always "". I made a simple test that demonstrates the error:

from googleapiclient import discovery, errors

client = discovery.build(
    "discovery", "v1"
)

req = client.apis().getRest(api='fake_api', version='v1')

try:
    resp = req.execute()
except errors.HttpError as err:
    print(f'Error details are currently: "{err.error_details}"')
    print(f'Exception string representation is: "{err}"')
    print(f'Error details are currently: "{err.error_details}"')

The output of the above code:

Error details are currently: ""
Exception string representation is: "<HttpError 404 when requesting https://www.googleapis.com/discovery/v1/apis/fake_api/v1/rest?alt=json returned "Requested entity was not found.". Details: "Requested entity was not found.">"
Error details are currently: "Requested entity was not found."

I tested and the behavior is the same on both google-api-python-client-1.12.8 and google-api-python-client-2.0.2

Activity

  1. self-assigned this
    on Mar 17, 2021
  2. added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    and removed
    triage meI really want to be triaged.
    on Mar 17, 2021
  3. added a commit that references this issue on Mar 17, 2021
    db2a766
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions