From fd8ae8ec9e33241ada584fcc6faefebf535a7ebf Mon Sep 17 00:00:00 2001 From: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> Date: Mon, 9 Nov 2026 23:38:23 +0530 Subject: [PATCH] fix(plugins): return the opsgenie and pagerduty incidents collector error CollectIncidents in both plugins returned nil when NewStatefulApiCollectorForFinalizableEntity failed, e.g. when the previous collector state couldn't be loaded or the cursor over unfinished incidents failed. The subtask was marked successful without collecting anything, and the error was lost. Return it, like the Opsgenie teams and users collectors do. Closes #9356 Generated-by: Claude Code (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 Signed-off-by: Shivam Sharma <192242476+ShivamSharma43@users.noreply.github.com> --- .../opsgenie/tasks/incidents_collector.go | 2 +- .../tasks/incidents_collector_test.go | 48 +++++++++++++++++++ .../pagerduty/tasks/incidents_collector.go | 2 +- .../tasks/incidents_collector_test.go | 48 +++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 backend/plugins/opsgenie/tasks/incidents_collector_test.go create mode 100644 backend/plugins/pagerduty/tasks/incidents_collector_test.go diff --git a/backend/plugins/opsgenie/tasks/incidents_collector.go b/backend/plugins/opsgenie/tasks/incidents_collector.go index 70100f149b9..6f346f19cb8 100644 --- a/backend/plugins/opsgenie/tasks/incidents_collector.go +++ b/backend/plugins/opsgenie/tasks/incidents_collector.go @@ -130,7 +130,7 @@ func CollectIncidents(taskCtx plugin.SubTaskContext) errors.Error { }, }) if err != nil { - return nil + return err } return collector.Execute() } diff --git a/backend/plugins/opsgenie/tasks/incidents_collector_test.go b/backend/plugins/opsgenie/tasks/incidents_collector_test.go new file mode 100644 index 00000000000..d0cfa0c8186 --- /dev/null +++ b/backend/plugins/opsgenie/tasks/incidents_collector_test.go @@ -0,0 +1,48 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tasks + +import ( + "testing" + + "github.com/apache/devlake/core/errors" + "github.com/apache/devlake/helpers/unithelper" + mockdal "github.com/apache/devlake/mocks/core/dal" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestCollectIncidentsReturnsCollectorSetupError(t *testing.T) { + // Loading the previous collector state fails, so the collector can't be created. + dbErr := errors.Default.New("db unavailable") + mockDal := new(mockdal.Dal) + mockDal.On("First", mock.Anything, mock.Anything).Return(dbErr).Once() + mockDal.On("IsErrorNotFound", dbErr).Return(false).Once() + + taskCtx := unithelper.DummySubTaskContext(mockDal) + taskCtx.On("GetData").Return(&OpsgenieTaskData{ + Options: &OpsgenieOptions{ConnectionId: 1, ServiceId: "service-1", ServiceName: "service"}, + }) + + err := CollectIncidents(taskCtx) + + if assert.NotNil(t, err) { + assert.Contains(t, err.Error(), "db unavailable") + } + mockDal.AssertExpectations(t) +} diff --git a/backend/plugins/pagerduty/tasks/incidents_collector.go b/backend/plugins/pagerduty/tasks/incidents_collector.go index 81cc2042689..6d1862cd14a 100644 --- a/backend/plugins/pagerduty/tasks/incidents_collector.go +++ b/backend/plugins/pagerduty/tasks/incidents_collector.go @@ -139,7 +139,7 @@ func CollectIncidents(taskCtx plugin.SubTaskContext) errors.Error { }, }) if err != nil { - return nil + return err } return collector.Execute() } diff --git a/backend/plugins/pagerduty/tasks/incidents_collector_test.go b/backend/plugins/pagerduty/tasks/incidents_collector_test.go new file mode 100644 index 00000000000..bc99d990c80 --- /dev/null +++ b/backend/plugins/pagerduty/tasks/incidents_collector_test.go @@ -0,0 +1,48 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package tasks + +import ( + "testing" + + "github.com/apache/devlake/core/errors" + "github.com/apache/devlake/helpers/unithelper" + mockdal "github.com/apache/devlake/mocks/core/dal" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/mock" +) + +func TestCollectIncidentsReturnsCollectorSetupError(t *testing.T) { + // Loading the previous collector state fails, so the collector can't be created. + dbErr := errors.Default.New("db unavailable") + mockDal := new(mockdal.Dal) + mockDal.On("First", mock.Anything, mock.Anything).Return(dbErr).Once() + mockDal.On("IsErrorNotFound", dbErr).Return(false).Once() + + taskCtx := unithelper.DummySubTaskContext(mockDal) + taskCtx.On("GetData").Return(&PagerDutyTaskData{ + Options: &PagerDutyOptions{ConnectionId: 1, ServiceId: "service-1", ServiceName: "service"}, + }) + + err := CollectIncidents(taskCtx) + + if assert.NotNil(t, err) { + assert.Contains(t, err.Error(), "db unavailable") + } + mockDal.AssertExpectations(t) +}