From 840f32d54121cf9f377d25f06003ad5c93db3a29 Mon Sep 17 00:00:00 2001 From: Bob Stevens <35038919+restevens402@users.noreply.github.com> Date: Thu, 15 Aug 2024 10:12:00 -0700 Subject: [PATCH] Refactor error handling and JSON tags in worker types Updated the error field in WorkResponse to a string as it should have been. Also, added JSON tags to struct fields for better JSON serialization. updated assignment of Error in handler functions to use formatted strings to conform to the data type change. --- pkg/api/handlers_data.go | 22 +++++++++++++---- pkg/workers/handlers/discord.go | 34 +++++++++++++++++++-------- pkg/workers/handlers/llm.go | 12 ++++++---- pkg/workers/handlers/telegram.go | 14 +++++++---- pkg/workers/handlers/twitter.go | 33 +++++++++++++++++++------- pkg/workers/handlers/web.go | 14 +++++++---- pkg/workers/types/request_response.go | 14 +++++------ pkg/workers/worker_manager.go | 32 ++++++++++++------------- 8 files changed, 116 insertions(+), 59 deletions(-) diff --git a/pkg/api/handlers_data.go b/pkg/api/handlers_data.go index c69e3521..bf83b97e 100644 --- a/pkg/api/handlers_data.go +++ b/pkg/api/handlers_data.go @@ -121,8 +121,9 @@ func handleWorkResponse(c *gin.Context, responseCh chan data_types.WorkResponse, for { select { case response := <-responseCh: - if response.Error != nil { + if response.Error != "" { c.JSON(http.StatusExpectationFailed, response) + wg.Done() return } if data, ok := response.Data.(string); ok && IsBase64(data) { @@ -139,16 +140,14 @@ func handleWorkResponse(c *gin.Context, responseCh chan data_types.WorkResponse, } response.Data = jsonData } - response.WorkRequest = data_types.WorkRequest{} + response.WorkRequest = &data_types.WorkRequest{} c.JSON(http.StatusOK, response) wg.Done() return case <-time.After(cfg.WorkerResponseTimeout): c.JSON(http.StatusGatewayTimeout, gin.H{"error": "Request timed out in API layer"}) - wg.Done() return case <-c.Done(): - wg.Done() return } } @@ -238,6 +237,7 @@ func (api *API) SearchTweetsAndAnalyzeSentiment() gin.HandlerFunc { if wErr != nil { c.JSON(http.StatusBadRequest, gin.H{"error": wErr.Error()}) } + wg.Wait() } } @@ -290,6 +290,8 @@ func (api *API) SearchDiscordMessagesAndAnalyzeSentiment() gin.HandlerFunc { c.JSON(http.StatusBadRequest, gin.H{"error": wErr.Error()}) return } + wg.Wait() + } } @@ -342,6 +344,7 @@ func (api *API) SearchTelegramMessagesAndAnalyzeSentiment() gin.HandlerFunc { c.JSON(http.StatusBadRequest, gin.H{"error": wErr.Error()}) return } + wg.Wait() } } @@ -432,6 +435,7 @@ func (api *API) SearchTweetsProfile() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -468,6 +472,7 @@ func (api *API) SearchDiscordProfile() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -514,6 +519,7 @@ func (api *API) SearchChannelMessages() gin.HandlerFunc { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) return } + wg.Wait() } } @@ -546,6 +552,7 @@ func (api *API) SearchGuildChannels() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -569,6 +576,7 @@ func (api *API) SearchUserGuilds() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -736,6 +744,7 @@ func (api *API) SearchTwitterFollowers() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -776,6 +785,7 @@ func (api *API) SearchTweetsRecent() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -796,6 +806,7 @@ func (api *API) SearchTweetsTrends() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -844,6 +855,7 @@ func (api *API) WebData() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -928,6 +940,7 @@ func (api *API) GetChannelMessagesHandler() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } @@ -983,6 +996,7 @@ func (api *API) LocalLlmChat() gin.HandlerFunc { if err != nil { c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()}) } + wg.Wait() } } diff --git a/pkg/workers/handlers/discord.go b/pkg/workers/handlers/discord.go index 853ab0b5..4dfd3d14 100644 --- a/pkg/workers/handlers/discord.go +++ b/pkg/workers/handlers/discord.go @@ -20,11 +20,14 @@ func (h *DiscordProfileHandler) HandleWork(data []byte) data_types.WorkResponse logrus.Infof("[+] DiscordProfileHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse discord json data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse discord json data: %v", err)} } userID := dataMap["userID"].(string) resp, err := discord.GetUserProfile(userID) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Data: resp, Error: fmt.Sprintf("unable to get discord user profile: %v", err)} + } + return data_types.WorkResponse{Data: resp} } // HandleWork implements the WorkHandler interface for DiscordChannelHandler. @@ -32,13 +35,16 @@ func (h *DiscordChannelHandler) HandleWork(data []byte) data_types.WorkResponse logrus.Infof("[+] DiscordChannelHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse discord json data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse discord json data: %v", err)} } channelID := dataMap["channelID"].(string) limit := dataMap["limit"].(string) prompt := dataMap["prompt"].(string) resp, err := discord.GetChannelMessages(channelID, limit, prompt) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get discord channel messages: %v", err)} + } + return data_types.WorkResponse{Data: resp} } // HandleWork implements the WorkHandler interface for DiscordSentimentHandler. @@ -46,14 +52,16 @@ func (h *DiscordSentimentHandler) HandleWork(data []byte) data_types.WorkRespons logrus.Infof("[+] DiscordSentimentHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse discord json data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse discord json data: %v", err)} } channelID := dataMap["channelID"].(string) model := dataMap["model"].(string) prompt := dataMap["prompt"].(string) _, resp, err := discord.ScrapeDiscordMessagesForSentiment(channelID, model, prompt) - - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get discord channel messages: %v", err)} + } + return data_types.WorkResponse{Data: resp} } // HandleWork implements the WorkHandler interface for DiscordGuildHandler. @@ -61,15 +69,21 @@ func (h *DiscordGuildHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] DiscordGuildHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse discord json data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse discord json data: %v", err)} } guildID := dataMap["guildID"].(string) resp, err := discord.GetGuildChannels(guildID) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get discord guild channels: %v", err)} + } + return data_types.WorkResponse{Data: resp} } func (h *DiscoreUserGuildsHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] DiscordUserGuildsHandler %s", data) resp, err := discord.GetUserGuilds() - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get discord user guilds: %v", err)} + } + return data_types.WorkResponse{Data: resp} } diff --git a/pkg/workers/handlers/llm.go b/pkg/workers/handlers/llm.go index fee93efa..658fcf77 100644 --- a/pkg/workers/handlers/llm.go +++ b/pkg/workers/handlers/llm.go @@ -2,7 +2,6 @@ package handlers import ( "encoding/json" - "errors" "fmt" "github.com/sirupsen/logrus" @@ -29,18 +28,21 @@ func (h *LLMChatHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] LLM Chat %s", data) uri := config.GetInstance().LLMChatUrl if uri == "" { - return data_types.WorkResponse{Error: errors.New("missing env variable LLM_CHAT_URL")} + return data_types.WorkResponse{Error: "missing env variable LLM_CHAT_URL"} } var dataMap map[string]interface{} if err := json.Unmarshal(data, &dataMap); err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse LLM chat data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse LLM chat data: %v", err)} } jsnBytes, err := json.Marshal(dataMap) if err != nil { - return data_types.WorkResponse{Error: err} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to marshal LLM chat data: %v", err)} } resp, err := Post(uri, jsnBytes, nil) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to post LLM chat data: %v", err)} + } + return data_types.WorkResponse{Data: resp} } diff --git a/pkg/workers/handlers/telegram.go b/pkg/workers/handlers/telegram.go index 6159bf2a..234e3ee0 100644 --- a/pkg/workers/handlers/telegram.go +++ b/pkg/workers/handlers/telegram.go @@ -18,13 +18,16 @@ func (h *TelegramSentimentHandler) HandleWork(data []byte) data_types.WorkRespon logrus.Infof("[+] TelegramSentimentHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse telegram json data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse telegram json data: %v", err)} } userName := dataMap["username"].(string) model := dataMap["model"].(string) prompt := dataMap["prompt"].(string) _, resp, err := telegram.ScrapeTelegramMessagesForSentiment(context.Background(), userName, model, prompt) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get telegram sentiment: %v", err)} + } + return data_types.WorkResponse{Data: resp} } // HandleWork implements the WorkHandler interface for TelegramChannelHandler. @@ -32,9 +35,12 @@ func (h *TelegramChannelHandler) HandleWork(data []byte) data_types.WorkResponse logrus.Infof("[+] TelegramChannelHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse telegram json data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse telegram json data: %v", err)} } userName := dataMap["username"].(string) resp, err := telegram.FetchChannelMessages(context.Background(), userName) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get telegram channel messages: %v", err)} + } + return data_types.WorkResponse{Data: resp} } diff --git a/pkg/workers/handlers/twitter.go b/pkg/workers/handlers/twitter.go index 5a495088..6db38d2d 100644 --- a/pkg/workers/handlers/twitter.go +++ b/pkg/workers/handlers/twitter.go @@ -19,52 +19,67 @@ func (h *TwitterQueryHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] TwitterQueryHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse twitter query data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse twitter query data: %v", err)} } count := int(dataMap["count"].(float64)) query := dataMap["query"].(string) resp, err := twitter.ScrapeTweetsByQuery(query, count) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get twitter query: %v", err)} + } + return data_types.WorkResponse{Data: resp} } func (h *TwitterFollowersHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] TwitterFollowersHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse twitter followers data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse twitter followers data: %v", err)} } username := dataMap["username"].(string) count := int(dataMap["count"].(float64)) resp, err := twitter.ScrapeFollowersForProfile(username, count) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get twitter followers: %v", err)} + } + return data_types.WorkResponse{Data: resp} } func (h *TwitterProfileHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] TwitterProfileHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse twitter profile data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse twitter profile data: %v", err)} } username := dataMap["username"].(string) resp, err := twitter.ScrapeTweetsProfile(username) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get twitter profile: %v", err)} + } + return data_types.WorkResponse{Data: resp} } func (h *TwitterSentimentHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] TwitterSentimentHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse twitter sentiment data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse twitter sentiment data: %v", err)} } count := int(dataMap["count"].(float64)) query := dataMap["query"].(string) model := dataMap["model"].(string) _, resp, err := twitter.ScrapeTweetsForSentiment(query, count, model) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get twitter sentiment: %v", err)} + } + return data_types.WorkResponse{Data: resp} } func (h *TwitterTrendsHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] TwitterTrendsHandler %s", data) resp, err := twitter.ScrapeTweetsByTrends() - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get twitter trends: %v", err)} + } + return data_types.WorkResponse{Data: resp} } diff --git a/pkg/workers/handlers/web.go b/pkg/workers/handlers/web.go index 8c21636a..393fd7f9 100644 --- a/pkg/workers/handlers/web.go +++ b/pkg/workers/handlers/web.go @@ -17,25 +17,31 @@ func (h *WebHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] WebHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse web data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse web data: %v", err)} } depth := int(dataMap["depth"].(float64)) urls := []string{dataMap["url"].(string)} resp, err := web.ScrapeWebData(urls, depth) - return data_types.WorkResponse{Data: resp, Error: err} + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get web data: %v", err)} + } + return data_types.WorkResponse{Data: resp} } func (h *WebSentimentHandler) HandleWork(data []byte) data_types.WorkResponse { logrus.Infof("[+] WebSentimentHandler %s", data) dataMap, err := JsonBytesToMap(data) if err != nil { - return data_types.WorkResponse{Error: fmt.Errorf("unable to parse web sentiment data: %v", err)} + return data_types.WorkResponse{Error: fmt.Sprintf("unable to parse web sentiment data: %v", err)} } depth := int(dataMap["depth"].(float64)) urls := []string{dataMap["url"].(string)} model := dataMap["model"].(string) _, resp, err := web.ScrapeWebDataForSentiment(urls, depth, model) + if err != nil { + return data_types.WorkResponse{Error: fmt.Sprintf("unable to get web sentiment: %v", err)} + } rslt := make(map[string]interface{}) rslt["sentiment"] = resp - return data_types.WorkResponse{Data: rslt, Error: err} + return data_types.WorkResponse{Data: rslt} } diff --git a/pkg/workers/types/request_response.go b/pkg/workers/types/request_response.go index a6dcd5fa..359c63cb 100644 --- a/pkg/workers/types/request_response.go +++ b/pkg/workers/types/request_response.go @@ -16,14 +16,14 @@ type Worker struct { } type WorkRequest struct { - WorkType WorkerType - RequestId string - Data []byte + WorkType WorkerType `json:"workType,omitempty"` + RequestId string `json:"requestId,omitempty"` + Data []byte `json:"data,omitempty"` } type WorkResponse struct { - WorkRequest WorkRequest - Data interface{} - Error error - WorkerPeerId string + WorkRequest *WorkRequest `json:"workRequest,omitempty"` + Data interface{} `json:"data,omitempty"` + Error string `json:"error,omitempty"` + WorkerPeerId string `json:"workerPeerId,omitempty"` } diff --git a/pkg/workers/worker_manager.go b/pkg/workers/worker_manager.go index 3b9d6308..f266a86d 100644 --- a/pkg/workers/worker_manager.go +++ b/pkg/workers/worker_manager.go @@ -110,8 +110,8 @@ func (whm *WorkHandlerManager) DistributeWork(node *masa.OracleNode, workRequest remoteWorkersAttempted++ logrus.Infof("Attempting remote worker %s (attempt %d/%d)", worker.NodeData.PeerId, remoteWorkersAttempted, workerConfig.MaxRemoteWorkers) response := whm.sendWorkToWorker(node, worker, workRequest) - if response.Error != nil { - logrus.Errorf("error sending work to worker: %s", response.Error.Error()) + if response.Error != "" { + logrus.Errorf("error sending work to worker: %s", response.Error) logrus.Infof("Remote worker %s failed, moving to next worker", worker.NodeData.PeerId) continue } @@ -121,8 +121,8 @@ func (whm *WorkHandlerManager) DistributeWork(node *masa.OracleNode, workRequest if localWorker != nil { return whm.ExecuteWork(workRequest) } - if response.Error == nil { - response.Error = errors.New("no eligible workers found") + if response.Error != "" { + response.Error = "no eligible workers found" } return response } @@ -132,13 +132,13 @@ func (whm *WorkHandlerManager) sendWorkToWorker(node *masa.OracleNode, worker da defer cancel() // Cancel the context when done to release resources if err := node.Host.Connect(ctxWithTimeout, *worker.AddrInfo); err != nil { - response.Error = fmt.Errorf("failed to connect to remote peer %s: %v", worker.AddrInfo.ID.String(), err) + response.Error = fmt.Sprintf("failed to connect to remote peer %s: %v", worker.AddrInfo.ID.String(), err) return } else { logrus.Debugf("[+] Connection established with node: %s", worker.AddrInfo.ID.String()) stream, err := node.Host.NewStream(ctxWithTimeout, worker.AddrInfo.ID, config.ProtocolWithVersion(config.WorkerProtocol)) if err != nil { - response.Error = fmt.Errorf("error opening stream: %v", err) + response.Error = fmt.Sprintf("error opening stream: %v", err) return } defer func(stream network.Stream) { @@ -151,19 +151,19 @@ func (whm *WorkHandlerManager) sendWorkToWorker(node *masa.OracleNode, worker da // Write the request to the stream with length prefix bytes, err := json.Marshal(workRequest) if err != nil { - response.Error = fmt.Errorf("error marshaling work request: %v", err) + response.Error = fmt.Sprintf("error marshaling work request: %v", err) return } lengthBuf := make([]byte, 4) binary.BigEndian.PutUint32(lengthBuf, uint32(len(bytes))) _, err = stream.Write(lengthBuf) if err != nil { - response.Error = fmt.Errorf("error writing length to stream: %v", err) + response.Error = fmt.Sprintf("error writing length to stream: %v", err) return } _, err = stream.Write(bytes) if err != nil { - response.Error = fmt.Errorf("error writing to stream: %v", err) + response.Error = fmt.Sprintf("error writing to stream: %v", err) return } @@ -171,7 +171,7 @@ func (whm *WorkHandlerManager) sendWorkToWorker(node *masa.OracleNode, worker da lengthBuf = make([]byte, 4) _, err = io.ReadFull(stream, lengthBuf) if err != nil { - response.Error = fmt.Errorf("error reading response length: %v", err) + response.Error = fmt.Sprintf("error reading response length: %v", err) return } responseLength := binary.BigEndian.Uint32(lengthBuf) @@ -180,12 +180,12 @@ func (whm *WorkHandlerManager) sendWorkToWorker(node *masa.OracleNode, worker da responseBuf := make([]byte, responseLength) _, err = io.ReadFull(stream, responseBuf) if err != nil { - response.Error = fmt.Errorf("error reading response: %v", err) + response.Error = fmt.Sprintf("error reading response: %v", err) return } err = json.Unmarshal(responseBuf, &response) if err != nil { - response.Error = fmt.Errorf("error unmarshaling response: %v", err) + response.Error = fmt.Sprintf("error unmarshaling response: %v", err) return } } @@ -197,7 +197,7 @@ func (whm *WorkHandlerManager) sendWorkToWorker(node *masa.OracleNode, worker da func (whm *WorkHandlerManager) ExecuteWork(workRequest data_types.WorkRequest) (response data_types.WorkResponse) { handler, exists := whm.getWorkHandler(workRequest.WorkType) if !exists { - return data_types.WorkResponse{Error: ErrHandlerNotFound} + return data_types.WorkResponse{Error: ErrHandlerNotFound.Error()} } // Create a context with a 30-second timeout @@ -211,7 +211,7 @@ func (whm *WorkHandlerManager) ExecuteWork(workRequest data_types.WorkRequest) ( go func() { startTime := time.Now() workResponse := handler.HandleWork(workRequest.Data) - if workResponse.Error == nil { + if workResponse.Error == "" { duration := time.Since(startTime) whm.mu.Lock() handlerInfo := whm.handlers[workRequest.WorkType] @@ -225,7 +225,7 @@ func (whm *WorkHandlerManager) ExecuteWork(workRequest data_types.WorkRequest) ( select { case <-ctx.Done(): // Context timed out - return data_types.WorkResponse{Error: errors.New("work execution timed out")} + return data_types.WorkResponse{Error: "work execution timed out"} case response = <-responseChan: // Work completed within the timeout return response @@ -264,7 +264,7 @@ func (whm *WorkHandlerManager) HandleWorkerStream(stream network.Stream) { return } workResponse := whm.ExecuteWork(workRequest) - if workResponse.Error != nil { + if workResponse.Error == "" { logrus.Errorf("error from remote worker %s: executing work: %v", err) } workResponse.WorkerPeerId = stream.Conn().LocalPeer().String()