Skip to content

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

@xiak

Description

@xiak

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
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions