Merge pull request #1049 from mlaventure/provide-error-when-task-not-found
Update execution.getTask() to provide more fine grained error
This commit is contained in:
commit
c4da4ed393
@ -112,13 +112,8 @@ func (s *Service) Create(ctx context.Context, r *api.CreateTaskRequest) (*api.Cr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var container containers.Container
|
container, err := s.getContainer(ctx, r.ContainerID)
|
||||||
if err := s.db.View(func(tx *bolt.Tx) error {
|
if err != nil {
|
||||||
store := metadata.NewContainerStore(tx)
|
|
||||||
var err error
|
|
||||||
container, err = store.Get(ctx, r.ContainerID)
|
|
||||||
return err
|
|
||||||
}); err != nil {
|
|
||||||
switch {
|
switch {
|
||||||
case metadata.IsNotFound(err):
|
case metadata.IsNotFound(err):
|
||||||
return nil, grpc.Errorf(codes.NotFound, "container %v not found", r.ContainerID)
|
return nil, grpc.Errorf(codes.NotFound, "container %v not found", r.ContainerID)
|
||||||
@ -476,14 +471,38 @@ func (s *Service) writeContent(ctx context.Context, mediaType, ref string, r io.
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) getContainer(ctx context.Context, id string) (containers.Container, error) {
|
||||||
|
var container containers.Container
|
||||||
|
|
||||||
|
if err := s.db.View(func(tx *bolt.Tx) error {
|
||||||
|
store := metadata.NewContainerStore(tx)
|
||||||
|
var err error
|
||||||
|
container, err = store.Get(ctx, id)
|
||||||
|
return err
|
||||||
|
}); err != nil {
|
||||||
|
return containers.Container{}, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return container, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) getTask(ctx context.Context, id string) (plugin.Task, error) {
|
func (s *Service) getTask(ctx context.Context, id string) (plugin.Task, error) {
|
||||||
for _, r := range s.runtimes {
|
container, err := s.getContainer(ctx, id)
|
||||||
t, err := r.Get(ctx, id)
|
if err != nil {
|
||||||
if err == nil {
|
return nil, grpc.Errorf(codes.InvalidArgument, "task %v not found: %s", id, err.Error())
|
||||||
return t, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime, err := s.getRuntime(container.Runtime.Name)
|
||||||
|
if err != nil {
|
||||||
|
return nil, grpc.Errorf(codes.NotFound, "task %v not found: %s", id, err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
t, err := runtime.Get(ctx, id)
|
||||||
|
if err != nil {
|
||||||
return nil, grpc.Errorf(codes.NotFound, "task %v not found", id)
|
return nil, grpc.Errorf(codes.NotFound, "task %v not found", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
return t, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) getRuntime(name string) (plugin.Runtime, error) {
|
func (s *Service) getRuntime(name string) (plugin.Runtime, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user