forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
grpc: add error handling wrappers to client/server
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
- Loading branch information
1 parent
02fff48
commit 3f77f04
Showing
9 changed files
with
168 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package moby_buildkit_v1 | ||
|
||
import ( | ||
context "context" | ||
|
||
"github.com/moby/buildkit/solver/errdefs" | ||
grpc "google.golang.org/grpc" | ||
) | ||
|
||
func WrapServerErrors(srv ControlServer) ControlServer { | ||
return &wrappedServer{srv} | ||
} | ||
|
||
type wrappedServer struct { | ||
srv ControlServer | ||
} | ||
|
||
func (s *wrappedServer) DiskUsage(ctx context.Context, req *DiskUsageRequest) (*DiskUsageResponse, error) { | ||
r, err := s.srv.DiskUsage(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (s *wrappedServer) Prune(req *PruneRequest, ps Control_PruneServer) error { | ||
return errdefs.ToGRPC(s.srv.Prune(req, ps)) | ||
} | ||
func (s *wrappedServer) Solve(ctx context.Context, req *SolveRequest) (*SolveResponse, error) { | ||
r, err := s.srv.Solve(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (s *wrappedServer) Status(req *StatusRequest, ss Control_StatusServer) error { | ||
return errdefs.ToGRPC(s.srv.Status(req, ss)) | ||
} | ||
func (s *wrappedServer) Session(req Control_SessionServer) error { | ||
return errdefs.ToGRPC(s.srv.Session(req)) | ||
} | ||
func (s *wrappedServer) ListWorkers(ctx context.Context, req *ListWorkersRequest) (*ListWorkersResponse, error) { | ||
r, err := s.srv.ListWorkers(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
|
||
func WrapClientErrors(c ControlClient) ControlClient { | ||
return &wrappedClient{c} | ||
} | ||
|
||
type wrappedClient struct { | ||
c ControlClient | ||
} | ||
|
||
func (c *wrappedClient) DiskUsage(ctx context.Context, in *DiskUsageRequest, opts ...grpc.CallOption) (*DiskUsageResponse, error) { | ||
r, err := c.c.DiskUsage(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Prune(ctx context.Context, in *PruneRequest, opts ...grpc.CallOption) (Control_PruneClient, error) { | ||
r, err := c.c.Prune(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Solve(ctx context.Context, in *SolveRequest, opts ...grpc.CallOption) (*SolveResponse, error) { | ||
r, err := c.c.Solve(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Status(ctx context.Context, in *StatusRequest, opts ...grpc.CallOption) (Control_StatusClient, error) { | ||
r, err := c.c.Status(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Session(ctx context.Context, opts ...grpc.CallOption) (Control_SessionClient, error) { | ||
r, err := c.c.Session(ctx, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) ListWorkers(ctx context.Context, in *ListWorkersRequest, opts ...grpc.CallOption) (*ListWorkersResponse, error) { | ||
r, err := c.c.ListWorkers(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package moby_buildkit_v1_frontend | ||
|
||
import ( | ||
context "context" | ||
|
||
"github.com/moby/buildkit/solver/errdefs" | ||
grpc "google.golang.org/grpc" | ||
) | ||
|
||
func WrapServerErrors(srv LLBBridgeServer) LLBBridgeServer { | ||
return &wrappedServer{srv} | ||
} | ||
|
||
type wrappedServer struct { | ||
srv LLBBridgeServer | ||
} | ||
|
||
func (w *wrappedServer) ResolveImageConfig(ctx context.Context, req *ResolveImageConfigRequest) (*ResolveImageConfigResponse, error) { | ||
r, err := w.srv.ResolveImageConfig(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) Solve(ctx context.Context, req *SolveRequest) (*SolveResponse, error) { | ||
r, err := w.srv.Solve(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) ReadFile(ctx context.Context, req *ReadFileRequest) (*ReadFileResponse, error) { | ||
r, err := w.srv.ReadFile(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) ReadDir(ctx context.Context, req *ReadDirRequest) (*ReadDirResponse, error) { | ||
r, err := w.srv.ReadDir(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) StatFile(ctx context.Context, req *StatFileRequest) (*StatFileResponse, error) { | ||
r, err := w.srv.StatFile(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) Ping(ctx context.Context, req *PingRequest) (*PongResponse, error) { | ||
r, err := w.srv.Ping(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) Return(ctx context.Context, req *ReturnRequest) (*ReturnResponse, error) { | ||
r, err := w.srv.Return(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
func (w *wrappedServer) Inputs(ctx context.Context, req *InputsRequest) (*InputsResponse, error) { | ||
r, err := w.srv.Inputs(ctx, req) | ||
return r, errdefs.ToGRPC(err) | ||
} | ||
|
||
func WrapClientErrors(c LLBBridgeClient) LLBBridgeClient { | ||
return &wrappedClient{c} | ||
} | ||
|
||
type wrappedClient struct { | ||
c LLBBridgeClient | ||
} | ||
|
||
func (c *wrappedClient) ResolveImageConfig(ctx context.Context, in *ResolveImageConfigRequest, opts ...grpc.CallOption) (*ResolveImageConfigResponse, error) { | ||
r, err := c.c.ResolveImageConfig(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Solve(ctx context.Context, in *SolveRequest, opts ...grpc.CallOption) (*SolveResponse, error) { | ||
r, err := c.c.Solve(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) ReadFile(ctx context.Context, in *ReadFileRequest, opts ...grpc.CallOption) (*ReadFileResponse, error) { | ||
r, err := c.c.ReadFile(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) ReadDir(ctx context.Context, in *ReadDirRequest, opts ...grpc.CallOption) (*ReadDirResponse, error) { | ||
r, err := c.c.ReadDir(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) StatFile(ctx context.Context, in *StatFileRequest, opts ...grpc.CallOption) (*StatFileResponse, error) { | ||
r, err := c.c.StatFile(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Ping(ctx context.Context, in *PingRequest, opts ...grpc.CallOption) (*PongResponse, error) { | ||
r, err := c.c.Ping(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Return(ctx context.Context, in *ReturnRequest, opts ...grpc.CallOption) (*ReturnResponse, error) { | ||
r, err := c.c.Return(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} | ||
func (c *wrappedClient) Inputs(ctx context.Context, in *InputsRequest, opts ...grpc.CallOption) (*InputsResponse, error) { | ||
r, err := c.c.Inputs(ctx, in, opts...) | ||
return r, errdefs.FromGRPC(err) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.