google-ads-java icon indicating copy to clipboard operation
google-ads-java copied to clipboard

Catch InvalidArgumentException while GoogleAdsException expected when mutate

Open JiangYisong-96 opened this issue 6 months ago • 12 comments

### Problem Overview I currently frequently met the cases that when I am using GoogleAdsServiceClient.mutate method submitting list of MutateOperations, I caught InvalidArgumentException instead of GoogleAdsException. https://cloud.google.com/java/docs/reference/gax/latest/com.google.api.gax.rpc.InvalidArgumentException And the actual invalid info like POLICY_FINDING from textual asset, Duplication of campaign name or those should have thrown GoogleAdsException as expected. By following the guidelines in GoogleAds Docs, I am able to solve and extract error details from GoogleAdsException class type. But InvalidArgumentException seems have a different structure while I could only print the error message from InvalidArgumentException.getErrorDetails().toString()

### Latest Sample Error message: [Google] Mutate - InvalidArgumentException INVALID_ARGUMENT: ErrorDetails{rawErrorMessages=[type_url: "type.googleapis.com/google.ads.googleads.v19.errors.GoogleAdsFailure" value: "\n\306\001\n\003\240\004\002\022eThe resource has been disapproved since the policy summary includes policy topics of type PROHIBITED."@\022\025\n\021mutate_operations\030\000\022\027\n\025ad_group_ad_operation\022\b\n\006create\022\004\n\002ad*\026\032\024\n\022\020\002*\016CAPITALIZATION\nn\n\0028\003\022\027Resource was not found."O\022\025\n\021mutate_operations\030\001\022\035\n\033ad_group_ad_label_operation\022\b\n\006create\022\r\n\vad_group_ad\022\026TUNgUBK4VIVCzBjU5a3HJA" ]}

### Request Details

Click to expand full request/response detail

FAILURE REQUEST DETAIL. Request

MethodName: google.ads.googleads.v19.services.GoogleAdsService/Mutate Endpoint: googleads.googleapis.com:443 Headers: {developer-token=REDACTED, login-customer-id=8984689079, x-goog-api-client=gl-java/17.0.10__Oracle-Corporation gccl/36.1.0--protobuf-3 gapic/36.1.0 gax/2.63.1 grpc/1.70.0 protobuf/3} Body: customer_id: "4600599411" mutate_operations { ad_group_ad_operation { create { resource_name: "customers/4600599411/adGroupAds/183048342616~-1" status: ENABLED ad { responsive_search_ad { headlines { text: "Essenciais para Volta \303\240s Aulas" } headlines { text: "Loja completa: Volta \303\240s aulas" } headlines { text: "At\303\251 90%OFF em material escolar" } headlines { text: "Ofertas Volta \303\240s Aulas" } headlines { text: "Promo\303\247\303\243o Volta \303\240s Aulas" } headlines { text: "Essenciais para a escola" } headlines { text: "Consiga seu Passe de Estilo" } headlines { text: "Estilo escolar com at\303\251 90% OFF" } headlines { text: "500mil looks p/ volta \303\240s aulas" } headlines { text: "Material escolar" } headlines { text: "Lista de material escolar" } headlines { text: "Economize na Volta \303\240s Aulas" } headlines { text: "Arrase na volta \303\240s aulas" } headlines { text: "Estilo escolar em sess\303\243o" } descriptions { text: "At\303\251 90% OFF em +500 mil best sellers da SHEIN \342\200\224 sua loja completa pra volta \303\240s aulas!" } descriptions { text: "Comece o ano letivo com itens essenciais com at\303\251 90% de desconto!" } descriptions { text: "Arrase com estilo com a SHEIN\342\200\224seu destino \303\272nico para a volta \303\240s aulas!" } descriptions { text: "Consiga o estilo com at\303\251 90% off em +de 500 mil itens essenciais para sua volta \303\240s aulas!" } } final_urls: "https://shein.com/onelink/14/4uxqtmdnv0ny?keyword={keyword}" name: "BR-PC-\345\223\201\347\211\214\350\257\215-20250721-91d460a8f8-adhub00009" } ad_group: "customers/4600599411/adGroups/183048342616" } } } mutate_operations { ad_group_ad_label_operation { create { ad_group_ad: "customers/4600599411/adGroupAds/183048342616~-1" label: "customers/4600599411/labels/22052432566" } } } response_content_type: MUTABLE_RESOURCE

Response

Headers: Metadata(content-type=application/grpc,request-id=TUNgUBK4VIVCzBjU5a3HJA,date=Thu, 17 Jul 2025 07:25:28 GMT,alt-svc=h3=":443"; ma=2592000,h3-29=":443"; ma=2592000) Body: null Failure message: errors { error_code { policy_finding_error: POLICY_FINDING } message: "The resource has been disapproved since the policy summary includes policy topics of type PROHIBITED." location { field_path_elements { field_name: "mutate_operations" index: 0 } field_path_elements { field_name: "ad_group_ad_operation" } field_path_elements { field_name: "create" } field_path_elements { field_name: "ad" } } details { policy_finding_details { policy_topic_entries { type: PROHIBITED topic: "CAPITALIZATION" } } } } errors { error_code { mutate_error: RESOURCE_NOT_FOUND } message: "Resource was not found." location { field_path_elements { field_name: "mutate_operations" index: 1 } field_path_elements { field_name: "ad_group_ad_label_operation" } field_path_elements { field_name: "create" } field_path_elements { field_name: "ad_group_ad" } } } request_id: "TUNgUBK4VIVCzBjU5a3HJA"

Status: Status{code=INVALID_ARGUMENT, description=Request contains an invalid argument., cause=null}.

Stack Trace

Expand to view full stack trace

[Google] Campaign - Exception occurred during creating ad_group_ad [2497797]: com.google.api.gax.rpc.InvalidArgumentException: io.grpc.StatusRuntimeException: INVALID_ARGUMENT: Request contains an invalid argument. at com.google.api.gax.rpc.ApiExceptionFactory.createException(ApiExceptionFactory.java:92) at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:98) at com.google.api.gax.grpc.GrpcApiExceptionFactory.create(GrpcApiExceptionFactory.java:66) at com.google.api.gax.grpc.GrpcExceptionCallable$ExceptionTransformingFuture.onFailure(GrpcExceptionCallable.java:97) at com.google.api.core.ApiFutures$1.onFailure(ApiFutures.java:84) at com.google.common.util.concurrent.Futures$CallbackListener.run(Futures.java:1132) at com.google.common.util.concurrent.DirectExecutor.execute(DirectExecutor.java:31) at com.google.common.util.concurrent.AbstractFuture.executeListener(AbstractFuture.java:1307) at com.google.common.util.concurrent.AbstractFuture.complete(AbstractFuture.java:1070) at com.google.common.util.concurrent.AbstractFuture.setException(AbstractFuture.java:819) at io.grpc.stub.ClientCalls$GrpcFuture.setException(ClientCalls.java:651) at io.grpc.stub.ClientCalls$UnaryStreamToFuture.onClose(ClientCalls.java:621) at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) at com.google.api.gax.grpc.ChannelPool$ReleasingClientCall$1.onClose(ChannelPool.java:569) at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) at com.google.ads.googleads.lib.logging.LoggingInterceptor$1$1.onClose(LoggingInterceptor.java:113) at io.grpc.PartialForwardingClientCallListener.onClose(PartialForwardingClientCallListener.java:39) at io.grpc.ForwardingClientCallListener.onClose(ForwardingClientCallListener.java:23) at io.grpc.ForwardingClientCallListener$SimpleForwardingClientCallListener.onClose(ForwardingClientCallListener.java:40) at com.google.api.gax.grpc.GrpcLoggingInterceptor$1$1.onClose(GrpcLoggingInterceptor.java:98) at io.grpc.internal.DelayedClientCall$DelayedListener$3.run(DelayedClientCall.java:489) at io.grpc.internal.DelayedClientCall$DelayedListener.delayOrExecute(DelayedClientCall.java:453) at io.grpc.internal.DelayedClientCall$DelayedListener.onClose(DelayedClientCall.java:486) at io.grpc.internal.ClientCallImpl.closeObserver(ClientCallImpl.java:564) at io.grpc.internal.ClientCallImpl.access$100(ClientCallImpl.java:72) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInternal(ClientCallImpl.java:729) at io.grpc.internal.ClientCallImpl$ClientStreamListenerImpl$1StreamClosed.runInContext(ClientCallImpl.java:710) at io.grpc.internal.ContextRunnable.run(ContextRunnable.java:37) at io.grpc.internal.SerializingExecutor.run(SerializingExecutor.java:133) at com.alibaba.ttl.TtlRunnable.run(TtlRunnable.java:60) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635) at java.base/java.lang.Thread.run(Thread.java:842) Suppressed: com.google.api.gax.rpc.AsyncTaskException: Asynchronous task failed at com.google.api.gax.rpc.ApiExceptions.callAndTranslateApiException(ApiExceptions.java:57) at com.google.api.gax.rpc.UnaryCallable.call(UnaryCallable.java:112) at com.google.ads.googleads.v19.services.GoogleAdsServiceClient.mutate(GoogleAdsServiceClient.java:596)

### Questions Is there any solutions to avoid getting InvalidArgumentException or convert InvalidArgumentException data to GoogleAdsException?

JiangYisong-96 avatar Jul 17 '25 07:07 JiangYisong-96