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

Throw error when there is no zero value in enum #201

Closed
wants to merge 2 commits into from

Conversation

BeLeap
Copy link
Member

@BeLeap BeLeap commented Apr 9, 2022

Make parser throw if there is no zero value in enum

PS. Please recommend something appropriate for error.

Closes #194

@BeLeap BeLeap self-assigned this Apr 9, 2022
return false
}
}, false) === false) {
throw new Error("enum must have field for 0.");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

according to the official docs,

enum definition must contain a constant that maps to zero as its first element. might be clearer.

@BeLeap
Copy link
Member Author

BeLeap commented Apr 9, 2022

I close this PR because it needs to work like this only in proto3, so I think I need to implement it again.

@BeLeap BeLeap closed this Apr 9, 2022
Comment on lines +868 to +875
if (statements.reduce((acc, statement) => {
switch (statement.type) {
case "enum-field":
return statement.fieldNumber.value.text === "0" || acc;
default:
return false
}
}, false) === false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think statements.filter(statement => statement === "enum-field").find(statement => statement.fieldNumber.value.text === "0") == null is better here.

Searching for field values for a single enum body is trivial, even if it's tens of thousands.

@BeLeap BeLeap deleted the fix/#194/enum-zero branch April 9, 2022 01:48
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

Successfully merging this pull request may close these issues.

pbkit doesn't throw Error on enum without zero value in "proto3"
2 participants