From d9ce2b5a1768aab6c2d7818bb669e27a9707aab4 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Sat, 5 Oct 2024 20:21:21 +0530 Subject: [PATCH 1/4] Prepare for a next patch release --- changelog.md | 6 ++++++ gradle.properties | 18 +++++++++--------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/changelog.md b/changelog.md index 4167d49..99bc3bc 100644 --- a/changelog.md +++ b/changelog.md @@ -4,6 +4,12 @@ This file contains all the notable changes done to the Ballerina protoc-tools pa The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.3.1] - 2024-10-07 + +### Fixed + +- [Fix the NPE when there is message field type of google.protobuf.Empty](https://github.com/ballerina-platform/ballerina-library/issues/7230) + ## [0.3.0] - 2024-06-27 ### Fixed diff --git a/gradle.properties b/gradle.properties index b8b6fc4..6dfe202 100644 --- a/gradle.properties +++ b/gradle.properties @@ -16,16 +16,16 @@ researchgateReleaseVersion=2.8.0 testngVersion=7.6.1 jacocoVersion=0.8.10 -stdlibGrpcVersion=1.11.1 -stdlibIoVersion=1.6.0 -stdlibTimeVersion=2.4.0 +stdlibGrpcVersion=1.11.2 +stdlibIoVersion=1.6.1 +stdlibTimeVersion=2.5.0 stdlibUrlVersion=2.4.0 -stdlibConstraintVersion=1.4.0 -stdlibCryptoVersion=2.7.0 +stdlibConstraintVersion=1.5.0 +stdlibCryptoVersion=2.7.2 stdlibLogVersion=2.9.0 stdlibOsVersion=1.8.0 -stdlibProtobufVersion=1.6.0 +stdlibProtobufVersion=1.6.1 stdlibRandomVersion=1.5.0 stdlibTaskVersion=2.5.0 @@ -34,11 +34,11 @@ stdlibFileVersion=1.9.0 stdlibMimeVersion=2.9.0 stdlibUuidVersion=1.8.0 -stdlibAuthVersion=2.11.0 -stdlibJwtVersion=2.11.0 +stdlibAuthVersion=2.11.2 +stdlibJwtVersion=2.12.1 stdlibOAuth2Version=2.11.0 -stdlibHttpVersion=2.11.0 +stdlibHttpVersion=2.11.4 # Ballerinax Observer observeVersion=1.2.3 From 7899a081dd95efc0e92431a77cfe3091598158a9 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Tue, 8 Oct 2024 11:09:13 +0530 Subject: [PATCH 2/4] Fix the issue in showing the actual error message --- .../protoc/protobuf/cmd/GrpcCmd.java | 8 +-- .../utils/BalFileGenerationUtils.java | 6 +- .../protoc/tools/ToolingUnaryTest.java | 7 +++ .../unary/schemaSyntaxErrors.proto | 61 +++++++++++++++++++ 4 files changed, 77 insertions(+), 5 deletions(-) create mode 100644 tooling-tests/src/test/resources/test-src/proto-files/unary/schemaSyntaxErrors.proto diff --git a/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/cmd/GrpcCmd.java b/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/cmd/GrpcCmd.java index 31a8d90..5a3d139 100644 --- a/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/cmd/GrpcCmd.java +++ b/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/cmd/GrpcCmd.java @@ -264,14 +264,14 @@ private void generateBalFile(String protoPath) { } } catch (CodeGeneratorException e) { String errorMessage = "An error occurred when generating the proto descriptor. " + e.getMessage(); - LOG.error("An error occurred when generating the proto descriptor.", e); outStream.println(errorMessage); + LOG.error("An error occurred when generating the proto descriptor.", e); return; } if (root.getDescriptor().length == 0) { String errorMsg = "An error occurred when generating the proto descriptor."; - LOG.error(errorMsg); outStream.println(errorMsg); + LOG.error(errorMsg); return; } LOG.debug("Successfully generated the root descriptor."); @@ -292,8 +292,8 @@ private void generateBalFile(String protoPath) { } catch (CodeGeneratorException e) { String errorMessage = "An error occurred when generating the dependent proto descriptor. " + e.getMessage(); - LOG.error(errorMessage, e); outStream.println(errorMessage); + LOG.error(errorMessage, e); return; } LOG.debug("Successfully generated the dependent descriptor."); @@ -316,10 +316,10 @@ private void generateBalFile(String protoPath) { } ballerinaFileBuilder.build(this.mode); } catch (CodeBuilderException | CodeGeneratorException | IOException e) { - LOG.error("Error generating the Ballerina file.", e); msg.append("Error generating the Ballerina file.").append(e.getMessage()) .append(BalGenerationConstants.NEW_LINE_CHARACTER); outStream.println(msg); + LOG.error("Error generating the Ballerina file.", e); return; } msg.append("Successfully generated the Ballerina file.").append(BalGenerationConstants.NEW_LINE_CHARACTER); diff --git a/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/utils/BalFileGenerationUtils.java b/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/utils/BalFileGenerationUtils.java index d915a42..9ea6beb 100644 --- a/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/utils/BalFileGenerationUtils.java +++ b/protoc-cli/src/main/java/io/ballerina/protoc/protobuf/utils/BalFileGenerationUtils.java @@ -80,7 +80,11 @@ public static ArrayList generateDescriptor(String command) throws CodeGe " running the protoc executor. " + e.getMessage(), e); } if (process.exitValue() != 0) { - handleProcessExecutionErrors(process); + StringBuilder errMsg = new StringBuilder(); + for (String line : output) { + errMsg.append(line).append(System.lineSeparator()); + } + throw new CodeGeneratorException("Process exited with the following output: \n" + errMsg); } return output; } diff --git a/tooling-tests/src/test/java/io/ballerina/protoc/tools/ToolingUnaryTest.java b/tooling-tests/src/test/java/io/ballerina/protoc/tools/ToolingUnaryTest.java index 9d46e98..75b211e 100644 --- a/tooling-tests/src/test/java/io/ballerina/protoc/tools/ToolingUnaryTest.java +++ b/tooling-tests/src/test/java/io/ballerina/protoc/tools/ToolingUnaryTest.java @@ -20,6 +20,7 @@ import org.testng.annotations.Test; +import static io.ballerina.protoc.tools.ToolingTestUtils.assertGeneratedDataTypeSourcesNegative; import static io.ballerina.protoc.tools.ToolingTestUtils.assertGeneratedSources; /** @@ -103,4 +104,10 @@ public void testUnaryWithEmptyFieldMessage() { "emptyFieldMessage_pb.bal", "testservice_service.bal", "testservice_client.bal", "tool_test_unary_11"); } + + @Test + public void testUnaryWithSchemaSyntaxErrors() { + assertGeneratedDataTypeSourcesNegative("unary", "schemaSyntaxErrors.proto", + "schemaSyntaxErrors_pb.bal", "tool_test_unary_12"); + } } diff --git a/tooling-tests/src/test/resources/test-src/proto-files/unary/schemaSyntaxErrors.proto b/tooling-tests/src/test/resources/test-src/proto-files/unary/schemaSyntaxErrors.proto new file mode 100644 index 0000000..a536dcf --- /dev/null +++ b/tooling-tests/src/test/resources/test-src/proto-files/unary/schemaSyntaxErrors.proto @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +syntax = "proto3"; + +package test; + +service TestService { + rpc TestRPC(RequestMessage) returns (ResponseMessage); +} + +enum TestEnum { + ENTRY_ONE = 0; + ENTRY_TWO = 1 +} + +message ComplexType { + uint32 foo = 1; + TestEnum bar = 2; +} + +message OptionalComplexType { + oneof value { + ComplexType complex_value = 1; + // A field to represent `None`. It's usually left as an empty field. + Empty none = 2; + } +} + +message OptionalString { + oneof value { + string name = 1; + // A field to represent `None`. It's usually left as an empty field. + Empty none = 2; + } +} + +message RequestMessage { + repeated OptionalComplexType req; +} + +message ResponseMessage { + repeated OptionalString resp = 1; +} + +message Empty From e4bc9bbd8cf855a6a4e03edcb48b01c13e7ad27e Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Tue, 8 Oct 2024 11:12:16 +0530 Subject: [PATCH 3/4] Update changelog.md --- changelog.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/changelog.md b/changelog.md index 99bc3bc..a1c0b7f 100644 --- a/changelog.md +++ b/changelog.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [Fix the NPE when there is message field type of google.protobuf.Empty](https://github.com/ballerina-platform/ballerina-library/issues/7230) +- [[Fix the issue in showing the actual error message](https://github.com/ballerina-platform/ballerina-library/issues/7238) + ## [0.3.0] - 2024-06-27 From 6baf5823dd354f0c69119f853c5b465f78c90ce6 Mon Sep 17 00:00:00 2001 From: Danesh Kuruppu Date: Tue, 8 Oct 2024 11:21:08 +0530 Subject: [PATCH 4/4] Update changelog.md --- changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelog.md b/changelog.md index a1c0b7f..1340a68 100644 --- a/changelog.md +++ b/changelog.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed - [Fix the NPE when there is message field type of google.protobuf.Empty](https://github.com/ballerina-platform/ballerina-library/issues/7230) -- [[Fix the issue in showing the actual error message](https://github.com/ballerina-platform/ballerina-library/issues/7238) +- [Fix the issue in showing the actual error message](https://github.com/ballerina-platform/ballerina-library/issues/7238) ## [0.3.0] - 2024-06-27