Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gapic-generator-java exits with IllegalStateException when there's no service in protos #2050

Closed
JoeWang1127 opened this issue Sep 28, 2023 · 5 comments · Fixed by #2460
Closed
Assignees
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@JoeWang1127
Copy link
Collaborator

The generator should return normally with no-op when there's no service in protos.

For example: when generating from google/cloud/alloydb/connectors/v1alpha, the generator exited with the following error:

Exception in thread "main" java.lang.IllegalStateException: No services found to generate
        at com.google.common.base.Preconditions.checkState(Preconditions.java:512)
        at com.google.api.generator.gapic.protoparser.Parser.parse(Parser.java:172)
        at com.google.api.generator.gapic.Generator.generateGapic(Generator.java:30)
        at com.google.api.generator.Main.main(Main.java:28)
--java_gapic_out: protoc-gen-java_gapic: Plugin failed with status code 1.
@JoeWang1127 JoeWang1127 added type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. priority: p2 Moderately-important priority. Fix may not be included in next release. labels Sep 28, 2023
@suztomo
Copy link
Member

suztomo commented Sep 28, 2023

I would implement the script in a way that it would not call gapic-generator-java if there's no need to call it.

@JoeWang1127
Copy link
Collaborator Author

I would implement the script in a way that it would not call gapic-generator-java if there's no need to call it.

I'm currently working on this feature.

However, generate_library.sh can't decide whether to invoke generator or not. This information is stored in BUILD.bazel: if there's no java_gapic_library target, then generate_library.sh should not call the generator.

The grpc java plugin is implemented in a way that if there's no service to generate, it will exit normally without generating any code. I think the generator (which is also a protoc plugin) should do the same.

@blakeli0
Copy link
Collaborator

We discussed this in the project meeting and I agree with Joe. In addition, we have other use cases that can benefit from this change. For example, as @mpeddada1 mentioned in #2048, we may need the generator to generate reflect-config.json for proto-only modules.

@blakeli0 blakeli0 added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Dec 26, 2023
@blakeli0
Copy link
Collaborator

This is working as intended, changing the type from bug to feature request.

@diegomarquezp
Copy link
Contributor

cc: @lqiu96 @JoeWang1127 @alicejli
We will address this issue by strictly causing a no-op (no output is generated) whenever no services are generated. We will leave the noop + reflect-config.json as a follow up to be addressed separately (#2048)

Some considerations:

  • Update documentation to explain that the generator will not fail but simply no-op
  • Add a log statement (stderr) indicating that no services will be generated

diegomarquezp added a commit that referenced this issue Jun 10, 2024
…tected (#2460)

Fixes #2050

Adds behavior to gracefully perform a NOOP if no services are contained
in the generation request.


## Confimation in hermetic build scripts

From `generate_library.sh` against `google/cloud/alloydb/connectors/v1`
```
+ /usr/local/google/home/diegomarquezp/Desktop/sdk2/sdk3/sdk-platform-java/library_generation/output/protobuf-25.2/bin/protoc --experimental_allow_proto3_optional --plugin=protoc-gen-java_gapic=/usr/local/google/home/diegomarquezp/.pyenv/versions/3.11.0/lib/python3.11/site-packages/library_generation/gapic-generator-java-wrapper --java_gapic_out=metadata:/usr/local/google/home/diegomarquezp/Desktop/sdk2/sdk3/sdk-platform-java/library_generation/output/temp_preprocessed/java_gapic_srcjar_raw.srcjar.zip --java_gapic_opt=transport=grpc,rest-numeric-enums,grpc-service-config=,gapic-config=,api-service-config=google/cloud/alloydb/connectors/v1/connectors_v1.yaml google/cloud/alloydb/connectors/v1/resources.proto google/cloud/common_resources.proto
Apr 05, 2024 9:33:22 PM com.google.api.generator.gapic.protoparser.Parser parse
WARNING: No services found to generate. This will produce an empty zip file
Apr 05, 2024 9:33:22 PM com.google.api.generator.gapic.composer.ClientLibraryPackageInfoComposer generatePackageInfo
WARNING: Generating empty package info since no services were found
+ did_generate_gapic=true
+ zipinfo -t /usr/local/google/home/diegomarquezp/Desktop/sdk2/sdk3/sdk-platform-java/library_generation/output/temp_preprocessed/java_gapic_srcjar_raw.srcjar.zip
Empty zipfile. 
+ did_generate_gapic=false
+ [[ false == \t\r\u\e ]]

```

I made some changes to library_generation but I moved them to a follow
up PR (#2599) so the
checks can pass here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
4 participants