How do you compare `ErrorCode`s?
See original GitHub issueIf I have the following:
results = ga_service.search(self.client_customer_id, query=query, page_size=page_size)
try:
yield from results
except GoogleAdsException as ex:
<'error handling here'>
There is a lot of information in ex
. The examples in this repo print the exception request_id
and the name of the status (ex.error.code().name
)
Instead of accessing the status, which can be general, I want to access the actual failures,
ex.failure.errors
.
for error in ex.failure.errors:
if error.code == <'not sure what to do here'>:
<'process individual failure'>
A use-case I have is that I want to trigger a certain code path if we receive a CLIENT_CUSTOMER_ID_INVALID
and a different one if we get a CUSTOMER_NOT_ACTIVE
. Using the StatusCode
, both of these errors have a status of UNAUTHENTICATED
.
My thoughts are that you need to create your own ErrorCode
, but I am not having success with that using
error_code = client.get_type('ErrorCode', version='v1')
Any ideas?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top Results From Across the Web
How to compare Go errors - Stack Overflow
If you currently compare errors using == , use errors.Is instead. Example: if err == io.ErrUnexpectedEOF. becomes if errors.Is(err, io.
Read more >Compare Data Tool Error Messages - Micro Focus
Error Message Description or Cause R...
Compare list file is empty Compare list file has no meaningful content. Ad...
Error in writing to file Error...
Read more >Comparing Go error values - Bitfield Consulting
The Error method on the error interface exists for humans, not code. The contents of that string belong in a log file, or...
Read more >Comparing error or error equality in Go (Golang)
Overview. First of all, what is meant by equality of the error? As you already know that error is represented by the error...
Read more >Comparison of different error-correcting codes. - ResearchGate
Table 1 summarizes the difference between the DIRC and sev- eral existing error-correction codes.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@j-walker23 @wesleybowman Thanks for coordinating with each other, and sorry for my delayed response. Is it accurate to describe the issue you’re having generally as wanting to lookup the string name of an Enum field using the integer value pulled from a request object?
It looks like that’s the core problem - if not, or if I’m leaving off other problems, please add on here.
The issue of doing this type of look up is definitely a major pain point. It’s possible to do this a bit more easily by using the protobuf helpers, like this:
Admittedly it’s not a whole lot better, but at least you don’t need to deal with the Enum protos directly.
One caveat about this solution is that it will generate errors if you are retrieving resource fields that contain a digit following an underscore, for example:
video_quartile_25_rate
. See this separate issue for more context: https://github.com/googleads/google-ads-python/issues/30I’m hoping to get functionality added to this library that will more easily expose the Enum field names so external helpers like
MessageToDict
aren’t necessary. Hopefully that will come in the near future.Let me know if you have any additional questions or thoughts here.
@wesleybowman Thank you for the explanation! I’m working on determining if there’s a way that we can improve the interface for this. To be honest it won’t be an easy change, so it might take some time. I’m going to close this issue since it’s not directly related, but I’ll open a new one to track progress against making Enums easier to work with.