Skip to content

[BUG] Mismatch in CamelCase Naming Between protoc-gen-go-errors and protoc-gen-go #3663

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

Open
xiak opened this issue May 14, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@xiak
Copy link

xiak commented May 14, 2025

What happened:

The CamelCase function in protoc-gen-go treats the boundary between letters and digits as a word boundary: when a letter follows a digit, that letter is capitalized.
However, protoc-gen-go-errors does not. It should be the same as the one used in protoc-gen-go, rather than rolling its own version; otherwise, it will lead to inconsistencies.

It will result in the following issues:

protoc-gen-go: Neo4JErrorReason_
error_errors.pb.go: Neo4jErrorReason_

syntax = "proto3";

package ads.service.application.error.v1;

import "errors/errors.proto";

option go_package = "ads-app/service/application/error/v1;v1";
option java_multiple_files = true;

enum Neo4jErrorReason {
    option (errors.default_code) = 500;

    UNKNOWN_ERROR = 0;
    INVALID_CONFIG = 1 [(errors.code) = 404];
    CONNECTION_FAILED = 2 [(errors.code) = 503];
    NO_RECORDS_AFFECTED = 3;
}

error.pb.go

// Code generated by protoc-gen-go. DO NOT EDIT.
const (
	Neo4JErrorReason_UNKNOWN_ERROR       Neo4JErrorReason = 0
	Neo4JErrorReason_INVALID_CONFIG      Neo4JErrorReason = 1
	Neo4JErrorReason_CONNECTION_FAILED   Neo4JErrorReason = 2
	Neo4JErrorReason_NO_RECORDS_AFFECTED Neo4JErrorReason = 3
)

error_errors.pb.go

// Code generated by protoc-gen-go-errors. DO NOT EDIT.
return e.Reason == Neo4jErrorReason_UNKNOWN_ERROR.String() && e.Code == 500
return e.Reason == Neo4jErrorReason_INVALID_CONFIG.String() && e.Code == 404
...

What you expected to happen:

How to reproduce it (as minimally and precisely as possible):

Anything else we need to know?:

In protoc-gen-go-errors, the camel‑case algorithm

// https://github.com/go-kratos/kratos/blob/main/cmd/protoc-gen-go-errors/errors.go
func case2Camel(name string) string {}

In protoc-gen-go, the camel‑case algorithm

// https://github.com/golang/protobuf/blob/master/protoc-gen-go/generator/generator.go
func CamelCase(s string) string {}

Environment:

  • Kratos version (use kratos -v): kratos version v2.8.4
  • Go version (use go version): go version go1.24.3 windows/amd64
  • OS (e.g: cat /etc/os-release): win/liunx
  • Others:
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// 	protoc-gen-go v1.36.6
// 	protoc        v5.28.0
// source: error.proto

type Neo4JErrorReason int32

const (
	Neo4JErrorReason_UNKNOWN_ERROR       Neo4JErrorReason = 0
	Neo4JErrorReason_INVALID_CONFIG      Neo4JErrorReason = 1
	Neo4JErrorReason_CONNECTION_FAILED   Neo4JErrorReason = 2
	Neo4JErrorReason_NO_RECORDS_AFFECTED Neo4JErrorReason = 3
)
@xiak xiak added the bug Something isn't working label May 14, 2025
Copy link

dosubot bot commented May 14, 2025

Hello @xiak! 👋 I'm Dosu, your friendly bot here to help you tackle bugs, answer questions, and guide you on your journey to becoming a contributor. I'm ready to assist you while you wait for a human maintainer!

To address the CamelCase naming mismatch between protoc-gen-go-errors and protoc-gen-go, you can modify the case2Camel function in the cmd/protoc-gen-go-errors/errors.go file to align with the behavior of the CamelCase function used in protoc-gen-go. The case2Camel function currently does not treat digits as word boundaries, which leads to inconsistencies like the ones you've observed.

Here's a brief overview of what you can do:

  1. Review the case2Camel function: This function is responsible for converting names to CamelCase in protoc-gen-go-errors. You can find it in the errors.go file of the Kratos framework.

  2. Align with protoc-gen-go: Ensure that the case2Camel function treats digits as word boundaries, similar to the CamelCase function in protoc-gen-go. This means capitalizing the letter following a digit.

  3. Testing: After making changes, verify the behavior with existing tests or add new tests to ensure the function behaves as expected.

By making these adjustments, you can achieve consistent CamelCase naming across both protoc-gen-go and protoc-gen-go-errors [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Bug Report | Other

@fifsky
Copy link
Contributor

fifsky commented May 14, 2025

In new protoc-gen-go

https://github.com/protocolbuffers/protobuf-go/blob/e5d44688be415e6cea6c21ebf5d832ab04378837/internal/strs/strings.go#L32
func GoCamelCase(s string) string

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants