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

Split gRPC and HTTP error utility into seperate packages #5

Merged
merged 1 commit into from
Apr 26, 2024

Conversation

austinvazquez
Copy link
Contributor

@austinvazquez austinvazquez commented Feb 9, 2024

Issue:

#4

Description:

By having a seperate packages, users can consume base package without pulling gRPC or HTTP as a dependency if not required.

This approach creates errgrpc and errhttp. The imports for users would be the following:

import (
    "github.com/containerd/errdefs"
    "github.com/containerd/errdefs/errgrpc"
    "github.com/containerd/errdefs/errhttp"
)

Other approaches considered:

Top level grpc and http packages. The imports for users would be the following:

import (
    "github.com/containerd/errdefs"
    "github.com/containerd/errdefs/grpc"
    "github.com/containerd/errdefs/http"
)

My thought was this may clutter the top level directory, but this may be acceptable as the number of protocol packages would be finite.

Testing:

Adds basic unit tests for there and back again error conversions for gRPC and HTTP error packages.

pkg/grpc/grpc.go Outdated
@@ -14,7 +14,7 @@
limitations under the License.
*/

package errdefs
package grpc
Copy link
Member

Choose a reason for hiding this comment

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

errdefs.FromGRPC should be now called like grpc.ToNative ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, grpc.FromGRPC can be redundant. grpc.ToNative is nice naming imo. Pushed to try it out.

Copy link
Member

Choose a reason for hiding this comment

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

Nit: maybe grpcerror or something?
I just dislike having package name conflicts that makes goimports trip up.

@austinvazquez austinvazquez changed the title Split gRPC error utility into seperate package Split gRPC and HTTP error utility into seperate packages Feb 9, 2024
@austinvazquez austinvazquez marked this pull request as ready for review February 9, 2024 16:47
@dmcgowan
Copy link
Member

Thanks for doing the split

Top level grpc and http packages. The imports for users would be the following:

+1 to keeping it at the top. I see pkg more for packages that could live on their own or not directly extending the root package.

Nit: maybe grpcerror or something?

+1 for keeping err (or error) in the package name (not the directory name). Maybe to be like...

import (
    "github.com/containerd/errdefs"
    errgrpc "github.com/containerd/errdefs/grpc"
    errhttp "github.com/containerd/errdefs/http"
)

?

@cpuguy83 that what you were thinking?

@cpuguy83
Copy link
Member

Not really, but that's fine.
For me I just end up fighting with goimports constantly with packages that have the same name and have to manually write the import statement.

@austinvazquez austinvazquez force-pushed the split-grpc-to-package branch 2 times, most recently from 334de29 to 8b9db8f Compare April 26, 2024 14:49
By having seperate packages, users can consume base package without pulling
gRPC or HTTP as a dependency if not required.

Signed-off-by: Austin Vazquez <macedonv@amazon.com>
@austinvazquez
Copy link
Contributor Author

@cpuguy83, @dmcgowan thanks for the suggestions. Pushed changes to address. Landed with errXXX package naming to avoid conflicts with common packages like http and grpc. LMK your thoughts.

@dmcgowan
Copy link
Member

Ok, works for me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

4 participants