From cc2b0374da2fd1d3b5d41af229657e3a1174ffa1 Mon Sep 17 00:00:00 2001 From: SoXX Date: Wed, 16 Oct 2024 10:22:35 +0200 Subject: [PATCH] fix: Refactor error handling by introducing errorString function to check for nil errors --- pkg/plug/grpc.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/pkg/plug/grpc.go b/pkg/plug/grpc.go index dc42706..0e415d6 100644 --- a/pkg/plug/grpc.go +++ b/pkg/plug/grpc.go @@ -130,10 +130,11 @@ func (s *server) TaskStart(ctx context.Context, creation *gRPC.PlugTaskCreation) ScrapeTaskID: models.ScrapeTaskID(id), UserSourceID: userSource.ID, FinishedAt: time.Now(), - Error: err.Error(), + Error: errorString(err), AddedPosts: taskSummery.AddedPosts, DeletedPosts: taskSummery.DeletedPosts, }) + if err != nil { log.WithContext(taskCtx).WithError(err).WithField("task_id", id).Error("Task execution failed") span.RecordError(err) @@ -293,3 +294,10 @@ func (s *server) removeTask(taskID string) { fn() delete(s.ctx, taskID) } + +func errorString(err error) string { + if err != nil { + return err.Error() + } + return "" +}