Skip to content

Commit 66157c9

Browse files
committed
chore(tasks): consolidate task errors into task_errors.go
1 parent 69542b1 commit 66157c9

17 files changed

+314
-295
lines changed

http/task_service.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,7 @@ func (h *TaskHandler) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
644644
Err: err,
645645
Msg: "failed to update task",
646646
}
647-
if err.Err == backend.ErrTaskNotFound {
647+
if err.Err == &influxdb.ErrTaskNotFound {
648648
err.Code = platform.ENotFound
649649
}
650650
EncodeError(ctx, err, w)
@@ -721,7 +721,7 @@ func (h *TaskHandler) handleDeleteTask(w http.ResponseWriter, r *http.Request) {
721721
Err: err,
722722
Msg: "failed to delete task",
723723
}
724-
if err.Err == backend.ErrTaskNotFound {
724+
if err.Err == &influxdb.ErrTaskNotFound {
725725
err.Code = platform.ENotFound
726726
}
727727
EncodeError(ctx, err, w)
@@ -798,7 +798,7 @@ func (h *TaskHandler) handleGetLogs(w http.ResponseWriter, r *http.Request) {
798798
Err: err,
799799
Msg: "failed to find task logs",
800800
}
801-
if err.Err == backend.ErrTaskNotFound || err.Err == backend.ErrNoRunsFound {
801+
if err.Err == &influxdb.ErrTaskNotFound || err.Err == &influxdb.ErrNoRunsFound {
802802
err.Code = platform.ENotFound
803803
}
804804
EncodeError(ctx, err, w)
@@ -890,7 +890,7 @@ func (h *TaskHandler) handleGetRuns(w http.ResponseWriter, r *http.Request) {
890890
Err: err,
891891
Msg: "failed to find runs",
892892
}
893-
if err.Err == backend.ErrTaskNotFound || err.Err == backend.ErrNoRunsFound {
893+
if err.Err == &influxdb.ErrTaskNotFound || err.Err == &influxdb.ErrNoRunsFound {
894894
err.Code = platform.ENotFound
895895
}
896896
EncodeError(ctx, err, w)
@@ -941,7 +941,7 @@ func decodeGetRunsRequest(ctx context.Context, r *http.Request) (*getRunsRequest
941941
}
942942

943943
if i < 1 || i > influxdb.TaskMaxPageSize {
944-
return nil, backend.ErrOutOfBoundsLimit
944+
return nil, &influxdb.ErrOutOfBoundsLimit
945945
}
946946
req.filter.Limit = i
947947
}
@@ -994,7 +994,7 @@ func (h *TaskHandler) handleForceRun(w http.ResponseWriter, r *http.Request) {
994994
Err: err,
995995
Msg: "failed to force run",
996996
}
997-
if err.Err == backend.ErrTaskNotFound {
997+
if err.Err == &influxdb.ErrTaskNotFound {
998998
err.Code = platform.ENotFound
999999
}
10001000
EncodeError(ctx, err, w)
@@ -1093,7 +1093,7 @@ func (h *TaskHandler) handleGetRun(w http.ResponseWriter, r *http.Request) {
10931093
Err: err,
10941094
Msg: "failed to find run",
10951095
}
1096-
if err.Err == backend.ErrTaskNotFound || err.Err == backend.ErrRunNotFound {
1096+
if err.Err == &influxdb.ErrTaskNotFound || err.Err == &influxdb.ErrRunNotFound {
10971097
err.Code = platform.ENotFound
10981098
}
10991099
EncodeError(ctx, err, w)
@@ -1199,7 +1199,7 @@ func (h *TaskHandler) handleCancelRun(w http.ResponseWriter, r *http.Request) {
11991199
Err: err,
12001200
Msg: "failed to cancel run",
12011201
}
1202-
if err.Err == backend.ErrTaskNotFound || err.Err == backend.ErrRunNotFound {
1202+
if err.Err == &influxdb.ErrTaskNotFound || err.Err == &influxdb.ErrRunNotFound {
12031203
err.Code = platform.ENotFound
12041204
}
12051205
EncodeError(ctx, err, w)
@@ -1250,7 +1250,7 @@ func (h *TaskHandler) handleRetryRun(w http.ResponseWriter, r *http.Request) {
12501250
Err: err,
12511251
Msg: "failed to retry run",
12521252
}
1253-
if err.Err == backend.ErrTaskNotFound || err.Err == backend.ErrRunNotFound {
1253+
if err.Err == &influxdb.ErrTaskNotFound || err.Err == &platform.ErrRunNotFound {
12541254
err.Code = platform.ENotFound
12551255
}
12561256
EncodeError(ctx, err, w)
@@ -1387,7 +1387,7 @@ func (t TaskService) FindTaskByID(ctx context.Context, id platform.ID) (*platfor
13871387
// ErrTaskNotFound is expected as part of the FindTaskByID contract,
13881388
// so return that actual error instead of a different error that looks like it.
13891389
// TODO cleanup backend task service error implementation
1390-
return nil, backend.ErrTaskNotFound
1390+
return nil, &influxdb.ErrTaskNotFound
13911391
}
13921392
return nil, err
13931393
}
@@ -1645,7 +1645,7 @@ func (t TaskService) FindRuns(ctx context.Context, filter platform.RunFilter) ([
16451645
}
16461646

16471647
if filter.Limit < 0 || filter.Limit > influxdb.TaskMaxPageSize {
1648-
return nil, 0, backend.ErrOutOfBoundsLimit
1648+
return nil, 0, &influxdb.ErrOutOfBoundsLimit
16491649
}
16501650
val.Set("limit", strconv.Itoa(filter.Limit))
16511651

@@ -1715,7 +1715,7 @@ func (t TaskService) FindRunByID(ctx context.Context, taskID, runID platform.ID)
17151715
// ErrRunNotFound is expected as part of the FindRunByID contract,
17161716
// so return that actual error instead of a different error that looks like it.
17171717
// TODO cleanup backend error implementation
1718-
return nil, backend.ErrRunNotFound
1718+
return nil, &platform.ErrRunNotFound
17191719
}
17201720

17211721
return nil, err
@@ -1759,7 +1759,7 @@ func (t TaskService) RetryRun(ctx context.Context, taskID, runID platform.ID) (*
17591759
// ErrRunNotFound is expected as part of the RetryRun contract,
17601760
// so return that actual error instead of a different error that looks like it.
17611761
// TODO cleanup backend task error implementation
1762-
return nil, backend.ErrRunNotFound
1762+
return nil, &platform.ErrRunNotFound
17631763
}
17641764
// RequestStillQueuedError is also part of the contract.
17651765
if e := backend.ParseRequestStillQueuedError(err.Error()); e != nil {
@@ -1806,7 +1806,7 @@ func (t TaskService) ForceRun(ctx context.Context, taskID platform.ID, scheduled
18061806
if platform.ErrorCode(err) == platform.ENotFound {
18071807
// ErrRunNotFound is expected as part of the RetryRun contract,
18081808
// so return that actual error instead of a different error that looks like it.
1809-
return nil, backend.ErrRunNotFound
1809+
return nil, &influxdb.ErrRunNotFound
18101810
}
18111811

18121812
// RequestStillQueuedError is also part of the contract.

http/task_service_test.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
802802
return &platform.Task{ID: taskID, Organization: "o"}, nil
803803
}
804804

805-
return nil, backend.ErrTaskNotFound
805+
return nil, &platform.ErrTaskNotFound
806806
},
807807
},
808808
method: http.MethodGet,
@@ -818,7 +818,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
818818
return &platform.Task{ID: taskID, Organization: "o"}, nil
819819
}
820820

821-
return nil, backend.ErrTaskNotFound
821+
return nil, &platform.ErrTaskNotFound
822822
},
823823
},
824824
method: http.MethodPatch,
@@ -835,7 +835,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
835835
return nil
836836
}
837837

838-
return backend.ErrTaskNotFound
838+
return &platform.ErrTaskNotFound
839839
},
840840
},
841841
method: http.MethodDelete,
@@ -851,7 +851,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
851851
return nil, 0, nil
852852
}
853853

854-
return nil, 0, backend.ErrTaskNotFound
854+
return nil, 0, &platform.ErrTaskNotFound
855855
},
856856
},
857857
method: http.MethodGet,
@@ -864,10 +864,10 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
864864
svc: &mock.TaskService{
865865
FindLogsFn: func(_ context.Context, f platform.LogFilter) ([]*platform.Log, int, error) {
866866
if f.Task != taskID {
867-
return nil, 0, backend.ErrTaskNotFound
867+
return nil, 0, &platform.ErrTaskNotFound
868868
}
869869
if *f.Run != runID {
870-
return nil, 0, backend.ErrNoRunsFound
870+
return nil, 0, &platform.ErrNoRunsFound
871871
}
872872

873873
return nil, 0, nil
@@ -883,7 +883,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
883883
svc: &mock.TaskService{
884884
FindRunsFn: func(_ context.Context, f platform.RunFilter) ([]*platform.Run, int, error) {
885885
if f.Task != taskID {
886-
return nil, 0, backend.ErrTaskNotFound
886+
return nil, 0, &platform.ErrTaskNotFound
887887
}
888888

889889
return nil, 0, nil
@@ -899,7 +899,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
899899
svc: &mock.TaskService{
900900
FindRunsFn: func(_ context.Context, f platform.RunFilter) ([]*platform.Run, int, error) {
901901
if f.Task != taskID {
902-
return nil, 0, backend.ErrNoRunsFound
902+
return nil, 0, &platform.ErrNoRunsFound
903903
}
904904

905905
return nil, 0, nil
@@ -915,7 +915,7 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
915915
svc: &mock.TaskService{
916916
ForceRunFn: func(_ context.Context, tid platform.ID, _ int64) (*platform.Run, error) {
917917
if tid != taskID {
918-
return nil, backend.ErrTaskNotFound
918+
return nil, &platform.ErrTaskNotFound
919919
}
920920

921921
return &platform.Run{ID: runID, TaskID: taskID, Status: backend.RunScheduled.String()}, nil
@@ -932,10 +932,10 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
932932
svc: &mock.TaskService{
933933
FindRunByIDFn: func(_ context.Context, tid, rid platform.ID) (*platform.Run, error) {
934934
if tid != taskID {
935-
return nil, backend.ErrTaskNotFound
935+
return nil, &platform.ErrTaskNotFound
936936
}
937937
if rid != runID {
938-
return nil, backend.ErrRunNotFound
938+
return nil, &platform.ErrRunNotFound
939939
}
940940

941941
return &platform.Run{ID: runID, TaskID: taskID, Status: backend.RunScheduled.String()}, nil
@@ -951,10 +951,10 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
951951
svc: &mock.TaskService{
952952
RetryRunFn: func(_ context.Context, tid, rid platform.ID) (*platform.Run, error) {
953953
if tid != taskID {
954-
return nil, backend.ErrTaskNotFound
954+
return nil, &platform.ErrTaskNotFound
955955
}
956956
if rid != runID {
957-
return nil, backend.ErrRunNotFound
957+
return nil, &platform.ErrRunNotFound
958958
}
959959

960960
return &platform.Run{ID: runID, TaskID: taskID, Status: backend.RunScheduled.String()}, nil
@@ -970,10 +970,10 @@ func TestTaskHandler_NotFoundStatus(t *testing.T) {
970970
svc: &mock.TaskService{
971971
CancelRunFn: func(_ context.Context, tid, rid platform.ID) error {
972972
if tid != taskID {
973-
return backend.ErrTaskNotFound
973+
return &platform.ErrTaskNotFound
974974
}
975975
if rid != runID {
976-
return backend.ErrRunNotFound
976+
return &platform.ErrRunNotFound
977977
}
978978

979979
return nil
@@ -1444,7 +1444,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
14441444

14451445
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*platform.Task, error) {
14461446
if id != taskID {
1447-
return nil, backend.ErrTaskNotFound
1447+
return nil, &platform.ErrTaskNotFound
14481448
}
14491449

14501450
return &platform.Task{
@@ -1536,7 +1536,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
15361536

15371537
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*platform.Task, error) {
15381538
if id != taskID {
1539-
return nil, backend.ErrTaskNotFound
1539+
return nil, &platform.ErrTaskNotFound
15401540
}
15411541

15421542
return &platform.Task{
@@ -1632,7 +1632,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
16321632

16331633
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*platform.Task, error) {
16341634
if id != taskID {
1635-
return nil, backend.ErrTaskNotFound
1635+
return nil, &platform.ErrTaskNotFound
16361636
}
16371637

16381638
return &platform.Task{
@@ -1727,7 +1727,7 @@ func TestTaskHandler_Sessions(t *testing.T) {
17271727

17281728
FindTaskByIDFn: func(ctx context.Context, id platform.ID) (*platform.Task, error) {
17291729
if id != taskID {
1730-
return nil, backend.ErrTaskNotFound
1730+
return nil, &platform.ErrTaskNotFound
17311731
}
17321732

17331733
return &platform.Task{

0 commit comments

Comments
 (0)