From 528f7547a5e880699ca6953b9f76d456e3bb4e8b Mon Sep 17 00:00:00 2001 From: Russell Troxel Date: Mon, 1 Jan 2024 21:15:47 -0800 Subject: [PATCH] Fix Existing Lints (#51) Signed-off-by: Russell Troxel --- internal/calibre/tasks/import.go | 18 ++++++++++++------ internal/middleware/logger_test.go | 6 +++--- internal/middleware/prometheus_test.go | 2 +- internal/task/scheduler_test.go | 2 +- internal/task/task.go | 4 +++- internal/tests/task_privacy_test.go | 2 +- 6 files changed, 21 insertions(+), 13 deletions(-) diff --git a/internal/calibre/tasks/import.go b/internal/calibre/tasks/import.go index c3f9f158..d51832e3 100644 --- a/internal/calibre/tasks/import.go +++ b/internal/calibre/tasks/import.go @@ -16,10 +16,6 @@ type importOutputCtxKey string const importOutputKey importOutputCtxKey = "importOutput" -type identifierKey struct { - typ, val string -} - type importContext struct { visitedAuthors map[int64]ksuid.ID visitedTags map[int64]ksuid.ID @@ -166,7 +162,12 @@ func ImportBooks(cal calibre.Calibre, client *ent.Client, ctx context.Context, c Msg("Failed to create book") ic.AddFailedBook(book.Title) } - cb(float64(idx+1) / (float64(total))) + if err := cb(float64(idx+1) / (float64(total))); err != nil { + log.Warn().Err(err). + Str("book", book.Title). + Int64("bookID", book.ID). + Msg("Failed to update progress") + } continue } @@ -217,7 +218,12 @@ func ImportBooks(cal calibre.Calibre, client *ent.Client, ctx context.Context, c Int64("bookID", book.ID). Msg("Failed to create series") } - cb(float64(idx+1) / (float64(total))) + if err := cb(float64(idx+1) / (float64(total))); err != nil { + log.Warn().Err(err). + Str("book", book.Title). + Int64("bookID", book.ID). + Msg("Failed to update progress") + } } return nil diff --git a/internal/middleware/logger_test.go b/internal/middleware/logger_test.go index a7bd9da3..30c4b292 100644 --- a/internal/middleware/logger_test.go +++ b/internal/middleware/logger_test.go @@ -28,7 +28,7 @@ func Test_StructuredLogger(t *testing.T) { { name: "200 OK", handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("OK")) + w.Write([]byte("OK")) // nolint: errcheck w.WriteHeader(http.StatusOK) }), expectedFunc: func() map[string]interface{} { @@ -72,7 +72,7 @@ func Test_StructuredLogger(t *testing.T) { logLine := make(map[string]interface{}) require.NoError( - json.Unmarshal([]byte(out.String()), &logLine), + json.Unmarshal(out.Bytes(), &logLine), ) require.NotEqual("", logLine["latency"]) for k, v := range tt.expectedFunc() { @@ -153,7 +153,7 @@ func Test_StructeredLoggerPathLogging(t *testing.T) { handle.ServeHTTP(httptest.NewRecorder(), httptest.NewRequest("GET", tt.path, nil)) logLine := make(map[string]interface{}) require.NoError( - json.Unmarshal([]byte(out.String()), &logLine), + json.Unmarshal(out.Bytes(), &logLine), ) require.Equal(tt.path, logLine["path"]) }) diff --git a/internal/middleware/prometheus_test.go b/internal/middleware/prometheus_test.go index f8b3a2fe..802d912a 100644 --- a/internal/middleware/prometheus_test.go +++ b/internal/middleware/prometheus_test.go @@ -18,7 +18,7 @@ func Test_PrometheusMiddleware(t *testing.T) { { name: "200 OK", handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Write([]byte("OK")) + w.Write([]byte("OK")) // nolint: errcheck w.WriteHeader(http.StatusOK) }), expectedMetrics: []string{ diff --git a/internal/task/scheduler_test.go b/internal/task/scheduler_test.go index b8ce7e7d..3dbf6565 100644 --- a/internal/task/scheduler_test.go +++ b/internal/task/scheduler_test.go @@ -68,7 +68,7 @@ func TestSchedulerSchedule(t *testing.T) { require.NoError(err) require.NotPanics(func() { - s.Schedule(ctx) + require.NoError(s.Schedule(ctx)) }) select { diff --git a/internal/task/task.go b/internal/task/task.go index 55ac183f..0dcc709c 100644 --- a/internal/task/task.go +++ b/internal/task/task.go @@ -56,6 +56,8 @@ func (t *concurrentTaskMap) RegisterTasks(taskMap TaskMap) { func NoOpTask(ctx context.Context, task *ent.Task, cb ProgressCallback) (msg string, err error) { log := log.Ctx(ctx) log.Info().Interface("task", task).Msg("NoOpTask") - cb(1) + if err := cb(1); err != nil { + return "", err + } return "done", nil } diff --git a/internal/tests/task_privacy_test.go b/internal/tests/task_privacy_test.go index 8d03da61..93ab5be1 100644 --- a/internal/tests/task_privacy_test.go +++ b/internal/tests/task_privacy_test.go @@ -153,7 +153,7 @@ func Test_UpdateSystemTask(t *testing.T) { SetType(task_enums.TypeNoOp). SetIsSystemTask(true). SaveX(adminCtx) - task, err := task.Update(). + _, err := task.Update(). SetProgress(0.5). Save(tt.updaterContext(data)) if tt.shouldUpdate {