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

acl: add ACL hostcalls #146

Merged
merged 4 commits into from
Dec 3, 2024
Merged

acl: add ACL hostcalls #146

merged 4 commits into from
Dec 3, 2024

Conversation

dgryski
Copy link
Member

@dgryski dgryski commented Nov 15, 2024

No description provided.

@dgryski
Copy link
Member Author

dgryski commented Nov 15, 2024

Note we can't merge this or run any tests until we have a viceroy release including fastly/Viceroy#438

// Not an error; we shouldn't get here
return fmt.Errorf("%w (%s)", ErrUnexpected, err)
case fastly.ACLErrorNoContent:
return ErrNoContent

Choose a reason for hiding this comment

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

In the context of Handle.Lookup, I wonder if something like ErrNoMatch would be more easily understood?

Copy link
Member Author

Choose a reason for hiding this comment

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

So replace ErrNoContent with a new error ErrNoMatch which improves the semenatic match but pulls it farther away from the underlying response code (and Rust SDK I guess).

Choose a reason for hiding this comment

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

Yes, agree that it pulls it further from the underlying response code. The Rust SDK uses Option<Response> with None when there's no match.

I think ErrNoContent is fine, but wanted to ask in case we could think of anything better.

Copy link
Member Author

Choose a reason for hiding this comment

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

The other way to represent "not found" would be to return a pointer to the entry, or a nil pointer (and no error) if it's not found. That puts the onus on the user, but they're already checking for error (and in fact maybe this is "nicer" since it doesn't conflate an error and a success-not-found case.)

Choose a reason for hiding this comment

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

Yes, I think using a pointer/nil could work and agree that it's not conflating errors with not-found cases. One final alternative would be to return something like:
(r Result, ok bool, err error)
where ok is false in the not-found case.

Copy link
Member Author

Choose a reason for hiding this comment

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

Rethinking this; I think I'm going to stick with returning an error. For example, Go's database/sql package returns ErrNoRows for query returning no rows. This is the same. And I want to stick with the error name in the wit file for consistency (and also in case things change in the future we won't end up in a situation where our SDK code drifts more from the underlying host calls.)

_examples/acl/main.go Show resolved Hide resolved
@dgryski dgryski force-pushed the dgryski/acl branch 2 times, most recently from eac0cdb to 90ebb49 Compare November 19, 2024 18:23
@dgryski dgryski merged commit 4dca515 into main Dec 3, 2024
11 checks passed
@dgryski dgryski deleted the dgryski/acl branch December 3, 2024 22:12
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.

2 participants