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

Discussion: Should we error here? #185

Open
chrismarget-j opened this issue Jan 12, 2024 · 7 comments
Open

Discussion: Should we error here? #185

chrismarget-j opened this issue Jan 12, 2024 · 7 comments
Assignees

Comments

@chrismarget-j
Copy link
Collaborator

getPropertySetsByLabel() returns an error if no matching property sets are found.

Should it?

It occurs to me that any expectation about the result count should fall to the caller, rather than to this function.

We probably have this pattern in many of the get<things>ByLabel() functions, I just happened to notice it here because I was using this code as a template for something else.

https://github.com/Juniper/apstra-go-sdk/blob/41d1f60c196d9efdec83e1b8b0e354c93e9d9f0f/apstra/api_property_sets.go#L119C1-L125C1

@rajagopalans
Copy link
Collaborator

If by caller you mean the ultimate consumer of the API, then yes, if I do a GetXByLabel and label does not exist I need a NotFound class of error. Same as a 404 not found on a website.
If by caller you mean the GetXByLabel method, I can see an argument for punting these error checks (none found/multiple found etc) to that layer. The use case would them be a workflow like 1.check if something exists 2. It does not exist, create it. Even in that case, you can do it by checking for the error as opposed to checking for a null value. My opinion is that it's a wash.

@chrismarget-j
Copy link
Collaborator Author

chrismarget-j commented Jan 12, 2024

I agree that the caller of GetPropertySetByLabel() or getPropertySetByLabel() should receive a NotFound error.

But I'm not so sure about the callers of the complimentary method which returns a slice.

"give me everything matching foo" <- an empty result is valid here, I think?

With the way we're currently using it, there's no difference because the two methods are tightly coupled.

Moving the check to here feels slightly more correct.

@rajagopalans
Copy link
Collaborator

getByLabel (or the public function) should return , err for none or multiple.
getByLabel should return [] empty list, single list or multiple in the list, with potentially no error at all.

I think we share code where both "get me everything matching this" and "get me one thing matching this" where the code raises no errors for the first and does error checks for the second.

I believe specifically for property sets, you cannot create more than one with the same name.

@chrismarget-j
Copy link
Collaborator Author

getByLabel should return [] empty list, single list or multiple in the list, with potentially no error at all.

Did you mean "getByLabels" here?

This discussion is mostly just pedantry. I'm looking at it purely from the perspective of "looking only at the function signature, does this function do what I expect?"

Thinking practically, we should probably deprecate all of the public GetByLabels methods since Apstra has been policing name collisions more aggressively with each new version. We should nudge SDK consumers away from thinking name collisions are okay.

I believe specifically for property sets, you cannot create more than one with the same name.

This is version dependent. Versions we have marked as "supported" do allow this.

@rajagopalans
Copy link
Collaborator

getByLabel should return [] empty list, single list or multiple in the list, with potentially no error at all.

Did you mean "getByLabels" here?
Something like getAllXByLabel getXByLabels implies a list of labels to search against.

This discussion is mostly just pedantry. I'm looking at it purely from the perspective of "looking only at the function signature, does this function do what I expect?"

Thinking practically, we should probably deprecate all of the public GetByLabels methods since Apstra has been policing name collisions more aggressively with each new version. We should nudge SDK consumers away from thinking name collisions are okay.
Yeah. GetAllXByLabel can return a list that can be empty GetXByLabel will error out if none or more than one exist of that same label.
We are saying ByLabel, but it could hold for ByName as well.

@chrismarget-j
Copy link
Collaborator Author

I see the confusion now.

Your previous comment used the same function name twice:

getByLabel (or the public function) should return , err for none or multiple.
getByLabel should return [] empty list, single list or multiple in the list, with potentially no error at all.

...and I added additional confusing by "fixing it" wrongly in my reply.

The missing distinction here isn't "label" vs. "labels", but "thing" vs. "things".

So, I think you originally meant this?

getThingByLabel (or the public function) should return , err for none or multiple.
getThingsByLabel should return [] empty list, single list or multiple in the list, with potentially no error at all.

@rajagopalans
Copy link
Collaborator

rajagopalans commented Jan 12, 2024 via email

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