AlexStocks commented on code in PR #3776:
URL: https://github.com/apache/dubbo-go/pull/3776#discussion_r4335429096


##########
tools/protoc-gen-triple-openapi/internal/converter/convert_test.go:
##########
@@ -35,6 +35,48 @@ import (
 
 var updateGolden = flag.Bool("update", false, "update OpenAPI golden files")
 
+func TestConvertInvalidParameters(t *testing.T) {

Review Comment:
   🟡 P2:新增的回归用例不会被任何 CI 作业执行,回归保护目前依赖人工。
   
   该目录是独立模块(`tools/protoc-gen-triple-openapi/go.mod` 声明 `module 
dubbo.apache.org/dubbo-go/v3/tools/protoc-gen-triple-openapi`)。取证链路:
   
   1. 根模块 `go list ./...` 不包含该模块的任何包(本次实测命中数 0),因此 `make test` / `make 
test-race`(`.github/workflows/github-actions.yml:78`、`:81`)覆盖不到这里;Makefile 的 
`test` 目标只额外执行 `cd $(CLI_DIR) && go test ./...`,而 `CLI_DIR = tools/dubbogo-cli`。
   2. 唯一由 `tools/**` 触发的工作流 `.github/workflows/tools.yml` 只有 3 
个作业:`Format`(`make fmt` + `git diff --exit-code`)、`Lint`(`make lint`,根模块 
`./...`)、`Generated CLI Projects`(构建 `tools/protoc-gen-go-triple` 与 
`tools/dubbogo-cli`),没有 test 作业。
   3. 对 5 个工作流文件检索 `triple-openapi`,命中 0 次,即该模块在 CI 中既不被测试也不被构建。
   
   这意味着本 PR 的核心价值(4 个回归用例)只存在于手工执行路径。建议在本 PR 或紧随的 follow-up 中新增一个作业(例如 `cd 
tools/protoc-gen-triple-openapi && go test ./... -count=1`),或把该模块并入 Makefile 的 
`test` 目标。补充一点:本 PR 的 Unit Test / Lint / Format 三项检查成功,并不代表这些用例被执行过。
   



##########
tools/protoc-gen-triple-openapi/internal/converter/convert.go:
##########
@@ -62,6 +62,9 @@ func ConvertFrom(r io.Reader) 
(*pluginpb.CodeGeneratorResponse, error) {
 
 func convert(req *pluginpb.CodeGeneratorRequest) 
(*pluginpb.CodeGeneratorResponse, error) {
        opts, err := options.Generate(req.GetParameter())
+       if err != nil {
+               return nil, err

Review Comment:
   💭 P3:错误呈现给 protoc 的方式可以更干净,不影响本修复的正确性。
   
   实测(protoc 35.1,`--triple-openapi_opt=unknown=1`):
   
   ```
   2026/10/21 17:56:12 Failed to convert from stdin: invalid parameter: 
unknown=1
   --triple-openapi_out: protoc-gen-triple-openapi: Plugin failed with status 
code 1.
   ```
   
   两点可改进:
   
   1. `Failed to convert from stdin` 这个前缀把参数错误归因到 stdin 读取(`main.go:49` 对 
`ConvertFrom` 的所有错误统一加此前缀),对使用者有误导。
   2. protoc 插件协议为「用户输入错误」提供了 `CodeGeneratorResponse.Error` 字段。设置它同样会让本次编译失败,但 
protoc 只输出一行 `--triple-openapi_out: <message>`,不会追加 `Plugin failed with status 
code 1.`,也不必走 `log.Fatalf` 的非零退出路径。
   
   若维护者倾向沿用现有 `log.Fatalf` 约定,建议至少让错误文案带上参数上下文。此项超出本 PR 的 3 行改动范围,可另开 issue 处理。
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to