Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Use package grpcio-status to parse rich errors in trailing metadata.  #99

Closed
@busunkim96

Description

@busunkim96

Package: https://pypi.org/project/grpcio-status/

Example: https://github.com/grpc/grpc/blob/master/examples/python/errors/client.py#L37

We are from IAM Policy Analyzer team and we've recently found that the python client library does not seems to surface the details in the Error Status properly. We've tried using gcloud and it works as expected. The comparison is as below:

$ gcloud beta asset analyze-iam-policy --project=cai-playground
ERROR: (gcloud.beta.asset.analyze-iam-policy) INVALID_ARGUMENT: Some specified value(s) are invalid.
- '@type': type.googleapis.com/google.rpc.BadRequest
  fieldViolations:
  - description: At least one of resource selector, identity selector or access selector
      needs to  be specified.
    field: analysis_query
$ gcloud auth application-default login
$ python3
 from google.cloud import asset_v1p4beta1
 from google.cloud.asset_v1p4beta1 import AnalyzeIamPolicyRequest, IamPolicyAnalysisQuery
 parent="projects/cai-playground"
 client = asset_v1p4beta1.AssetServiceClient()
 response = client.analyze_iam_policy(request=AnalyzeIamPolicyRequest(analysis_query=IamPolicyAnalysisQuery(parent=parent)))

Traceback (most recent call last):
  File "/usr/local/google/home/aaronlichen/.local/lib/python3.8/site-packages/google/api_core/grpc_helpers.py", line 57, in error_remapped_callable
    return callable_(*args, **kwargs)
  File "/usr/local/google/home/aaronlichen/.local/lib/python3.8/site-packages/grpc/_channel.py", line 826, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/google/home/aaronlichen/.local/lib/python3.8/site-packages/grpc/_channel.py", line 729, in _end_unary_response_blocking
    raise _InactiveRpcError(state)
grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with:
        status = StatusCode.INVALID_ARGUMENT
        details = "Some specified value(s) are invalid."
        debug_error_string = "{"created":"@1602024200.721639270","description":"Error received from peer ipv4:74.125.142.95:443","file":"src/core/lib/surface/call.cc","file_line":1061,"grpc_message":"Some specified value(s) are invalid.","grpc_status":3}"

Metadata

Metadata

Labels

type: feature request‘Nice-to-have’ improvement, new feature or different behavior or design.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions