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

Make UNSET enums' String() return "UNSET" #436

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

Conversation

wenovus
Copy link
Collaborator

@wenovus wenovus commented Aug 26, 2020

Returning this message for UNSET seems rather excessive, as reflected by a user: fmt.Sprintf("out-of-range %s enum value: %v", enumTypeName, val)

Since all UNSET values are currently 0, we can just use this fact to return "UNSET" if they're not found within the enum map.

@googlebot googlebot added the cla: yes This PR author has signed the CLA label Aug 26, 2020
@wenovus wenovus requested a review from robshakir August 26, 2020 18:28
@github-actions
Copy link

Coverage Status

Coverage increased (+0.002%) to 90.73% when pulling a4add04 on unset-enum-empty into b9d3c8f on master.

@wenovus
Copy link
Collaborator Author

wenovus commented Aug 26, 2020

Actually, I think UNSET might be better, since it might be used for logging. Seeing UNSET is probably better than the empty string.

@wenovus wenovus changed the title Make UNSET enums' String() return "" Make UNSET enums' String() return "UNSET" Aug 26, 2020
@robshakir
Copy link
Contributor

There was the intention to make the default value of an enumeration be the 0 value in the case that a default was specified for the leaf -- is that currently not-operational? If so, it would mean that UNSET as a string literal might not be the right thing to return.

@wenovus
Copy link
Collaborator Author

wenovus commented Sep 17, 2020

Since TogNMINotifications doesn't use the schema to determine the value to marshal, doesn't it mean that this is not operational?

func TogNMINotifications(s GoStruct, ts int64, cfg GNMINotificationsConfig) ([]*gnmipb.Notification, error) {

If we have a typedef enum used in multiple places, then in order to stream the correct default value, TogNMINotifications necessarily has to get this from the schema metadata.

@wenovus
Copy link
Collaborator Author

wenovus commented Sep 17, 2020

#172 confirms that this is not in operation in Go. It is also of dubious operation in proto due to the possibility of re-uses of enum typedefs. I think the question of how we're going to support default values in Go needs to be answered first before the concern raised in this PR can be answered.

@wenovus wenovus added the needs-discussion Needs Discussion on Next Steps label Oct 6, 2020
@robshakir robshakir added this to the 1.0.0 milestone Oct 15, 2020
@wenovus
Copy link
Collaborator Author

wenovus commented Jul 21, 2021

Just clarifying here that this PR is dependent on how #101 and specifically #172 are resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes This PR author has signed the CLA needs-discussion Needs Discussion on Next Steps
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants