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

First enum value must be 0 in proto3 [protoprint] #581

Closed
japersik opened this issue Nov 2, 2023 · 2 comments
Closed

First enum value must be 0 in proto3 [protoprint] #581

japersik opened this issue Nov 2, 2023 · 2 comments

Comments

@japersik
Copy link
Contributor

japersik commented Nov 2, 2023

Hi,
I found another invalid case in protoprinter.
If you make a negative identifier in enum (yes, it is possible), then after compiling into a descriptor something like this:

enum MY_ENUM {
    MY_ENUM_UNSPECIFIED = 0;
    MY_ENUM_ONE = 1;
    
    FIELD_NEGATIVE_ID = -1;
}

after using protoprint, it turns into

enum MY_ENUM {
    FIELD_NEGATIVE_ID = -1;
    MY_ENUM_UNSPECIFIED = 0;
    MY_ENUM_ONE = 1;
}

The fields are sorted in ascending order. As a result, we get an invalid proto3 file because First enum value must be 0 in proto3

@japersik
Copy link
Contributor Author

japersik commented Nov 2, 2023

It reproduce when

protoprint.Printer{
	SortElements: true
}

@jhump
Copy link
Owner

jhump commented Nov 2, 2023

Fixed in #582

@jhump jhump closed this as completed Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants