Skip to content

Commit 060d5d7

Browse files
committed
handle for pg no rows
1 parent 53e102a commit 060d5d7

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/configDiff/DeploymentConfigurationService.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
appRepository "github.com/devtron-labs/devtron/internal/sql/repository/app"
88
"github.com/devtron-labs/devtron/internal/sql/repository/chartConfig"
99
"github.com/devtron-labs/devtron/internal/sql/repository/pipelineConfig"
10+
"github.com/devtron-labs/devtron/internal/util"
1011
bean3 "github.com/devtron-labs/devtron/pkg/bean"
1112
chartService "github.com/devtron-labs/devtron/pkg/chart"
1213
"github.com/devtron-labs/devtron/pkg/cluster/repository"
@@ -27,6 +28,7 @@ import (
2728
util2 "github.com/devtron-labs/devtron/util"
2829
"github.com/go-pg/pg"
2930
"go.uber.org/zap"
31+
"net/http"
3032
)
3133

3234
type DeploymentConfigurationService interface {
@@ -175,9 +177,11 @@ func (impl *DeploymentConfigurationServiceImpl) getConfigDataForCdRollback(ctx c
175177
func (impl *DeploymentConfigurationServiceImpl) getDeploymentHistoryConfig(ctx context.Context, configDataQueryParams *bean2.ConfigDataQueryParams) (*bean2.DeploymentAndCmCsConfig, error) {
176178
deploymentJson := json.RawMessage{}
177179
deploymentHistory, err := impl.deploymentTemplateHistoryRepository.GetHistoryByPipelineIdAndWfrId(configDataQueryParams.PipelineId, configDataQueryParams.WfrId)
178-
if err != nil {
180+
if err != nil && !util.IsErrNoRows(err) {
179181
impl.logger.Errorw("error in getting deployment template history for pipelineId and wfrId", "pipelineId", configDataQueryParams.PipelineId, "wfrId", configDataQueryParams.WfrId, "err", err)
180182
return nil, err
183+
} else if util.IsErrNoRows(err) {
184+
return nil, util.GetApiError(http.StatusNotFound, bean2.NoDeploymentDoneForSelectedImage, bean2.NoDeploymentDoneForSelectedImage)
181185
}
182186
err = deploymentJson.UnmarshalJSON([]byte(deploymentHistory.Template))
183187
if err != nil {

pkg/configDiff/bean/bean.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,7 @@ type DeploymentTemplateMetadata struct {
227227
TemplateVersion string
228228
IsAppMetricsEnabled bool
229229
}
230+
231+
const (
232+
NoDeploymentDoneForSelectedImage = "there were no deployments done for the selected image"
233+
)

0 commit comments

Comments
 (0)