Skip to content

Commit

Permalink
fix: 500 fixes second iteration (#4464)
Browse files Browse the repository at this point in the history
* FetchChartNotes return 4xx when installed app or installed app versions not found

* GetDeploymentHistory and GetInstalledAppVersion to return 4xx when installed app or installed app versions not found

* fixes

* adding pg:",discard_unknown_columns" in tables where doesn't exist

* fix for Git Sensor response

* fix for inception

* fix for k8s resource delete

* fix for pipeline already exists

* fix for pipeline already exists

* fix

* fix

* fix

* fix

* go mod version changes

* merged

* common lib main version sync

* main merge

---------

Co-authored-by: ShashwatDadhich <dadhichshashwat1808@gmail.com>
  • Loading branch information
prakash100198 and ShashwatDadhich committed Jan 21, 2024
1 parent 897ffda commit 7cff679
Show file tree
Hide file tree
Showing 14 changed files with 33 additions and 13 deletions.
4 changes: 2 additions & 2 deletions api/appStore/deployment/CommonDeploymentRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (handler *CommonDeploymentRestHandlerImpl) getAppOfferingMode(installedAppI
}
installedAppDto, err = handler.appStoreDeploymentServiceC.GetInstalledAppByClusterNamespaceAndName(appIdentifier.ClusterId, appIdentifier.Namespace, appIdentifier.ReleaseName)
if err != nil {
err = &util.ApiError{HttpStatusCode: http.StatusInternalServerError, UserMessage: "unable to find app in database"}
err = &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: "unable to find app in database"}
return appOfferingMode, installedAppDto, err
}
// this is the case when hyperion apps does not linked yet
Expand All @@ -119,7 +119,7 @@ func (handler *CommonDeploymentRestHandlerImpl) getAppOfferingMode(installedAppI
}
installedAppDto, err = handler.appStoreDeploymentServiceC.GetInstalledAppByInstalledAppId(installedAppId)
if err != nil {
err = &util.ApiError{HttpStatusCode: http.StatusInternalServerError, UserMessage: "unable to find app in database"}
err = &util.ApiError{HttpStatusCode: http.StatusBadRequest, UserMessage: "unable to find app in database"}
return appOfferingMode, installedAppDto, err
}
} else {
Expand Down
12 changes: 11 additions & 1 deletion api/k8s/application/k8sApplicationRestHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/devtron-labs/common-lib/utils"
"net/http"
"strconv"
"strings"
Expand Down Expand Up @@ -512,8 +513,17 @@ func (handler *K8sApplicationRestHandlerImpl) DeleteResource(w http.ResponseWrit

resource, err := handler.k8sApplicationService.DeleteResourceWithAudit(r.Context(), &request, userId)
if err != nil {
errCode := http.StatusInternalServerError
if apiErr, ok := err.(*utils.ApiError); ok {
errCode = apiErr.HttpStatusCode
switch errCode {
case http.StatusNotFound:
errorMessage := "resource not found"
err = fmt.Errorf("%s: %w", errorMessage, err)
}
}
handler.logger.Errorw("error in deleting resource", "err", err)
common.WriteJsonResp(w, err, resource, http.StatusInternalServerError)
common.WriteJsonResp(w, err, resource, errCode)
return
}
common.WriteJsonResp(w, nil, resource, http.StatusOK)
Expand Down
4 changes: 3 additions & 1 deletion client/gitSensor/GitSensorGrpcClient.go
Original file line number Diff line number Diff line change
Expand Up @@ -335,10 +335,12 @@ func (client *GrpcApiClientImpl) GetCommitMetadataForPipelineMaterial(ctx contex
GitTag: req.GitTag,
BranchName: req.BranchName,
})

if err != nil {
return nil, err
}
if res == nil {

if res.Commit == "" {
return nil, nil
}

Expand Down
2 changes: 1 addition & 1 deletion internal/sql/repository/NotificationSettingsRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type NotificationSettingsViewWithAppEnv struct {
}

type NotificationSettings struct {
tableName struct{} `sql:"notification_settings"`
tableName struct{} `sql:"notification_settings" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
TeamId *int `sql:"team_id"`
AppId *int `sql:"app_id"`
Expand Down
2 changes: 1 addition & 1 deletion internal/sql/repository/WebhookEventDataRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

type WebhookEventData struct {
tableName struct{} `sql:"webhook_event_data"`
tableName struct{} `sql:"webhook_event_data" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
GitHostId int `sql:"git_host_id,notnull"`
EventType string `sql:"event_type,notnull"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1566,7 +1566,7 @@ func (impl AppStoreDeploymentServiceImpl) GetInstalledAppVersion(id int, userId
app, err := impl.installedAppRepository.GetInstalledAppVersion(id)
if err != nil {
if err == pg.ErrNoRows {
return nil, fmt.Errorf("values are outdated. please fetch the latest version and try again")
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}
}
impl.logger.Errorw("error while fetching from db", "error", err)
return nil, err
Expand Down
5 changes: 4 additions & 1 deletion pkg/appStore/deployment/service/InstalledAppService.go
Original file line number Diff line number Diff line change
Expand Up @@ -919,11 +919,14 @@ func (impl *InstalledAppServiceImpl) FetchChartNotes(installedAppId int, envId i
installedApp, err := impl.installedAppRepository.FetchNotes(installedAppId)
if err != nil && err != pg.ErrNoRows {
return "", err
} else if err == pg.ErrNoRows {
impl.logger.Errorw("installed app not found or may have been deleted", "installedAppId", installedAppId, "envId", envId)
return "", &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "Installed app not found in database or may have been deleted", InternalMessage: err.Error()}
}
installedAppVerison, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdAndEnvId(installedAppId, envId)
if err != nil {
if err == pg.ErrNoRows {
return "", fmt.Errorf("values are outdated. please fetch the latest version and try again")
return "", &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}
}
impl.logger.Errorw("error fetching installed app version in installed app service", "err", err)
return "", err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ func (impl AppStoreDeploymentArgoCdServiceImpl) GetDeploymentHistory(ctx context
installedAppVersions, err := impl.installedAppRepository.GetInstalledAppVersionByInstalledAppIdMeta(installedAppDto.InstalledAppId)
if err != nil {
if err == pg.ErrNoRows {
return nil, fmt.Errorf("values are outdated. please fetch the latest version and try again")
return nil, &util.ApiError{HttpStatusCode: http.StatusBadRequest, Code: "400", UserMessage: "values are outdated. please fetch the latest version and try again", InternalMessage: err.Error()}
}
impl.Logger.Errorw("error while fetching installed version", "error", err)
return result, err
Expand Down
2 changes: 1 addition & 1 deletion pkg/chartRepo/repository/ChartRepoRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type ChartRepoFields struct {
AllowInsecureConnection bool `sql:"allow_insecure_connection"`
}
type ChartRepo struct {
tableName struct{} `sql:"chart_repo"`
tableName struct{} `sql:"chart_repo" pg:",discard_unknown_columns"`
ChartRepoFields
sql.AuditLog
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
)

type ExternalLinkIdentifierMapping struct {
tableName struct{} `sql:"external_link_identifier_mapping"`
tableName struct{} `sql:"external_link_identifier_mapping" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
ExternalLinkId int `sql:"external_link_id,notnull"`
Type AppIdentifier `sql:"type,notnull"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/externalLink/ExternalLinkMonitoringToolRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

type ExternalLinkMonitoringTool struct {
tableName struct{} `sql:"external_link_monitoring_tool"`
tableName struct{} `sql:"external_link_monitoring_tool" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
Name string `sql:"name,notnull"`
Icon string `sql:"icon,notnull"`
Expand Down
2 changes: 1 addition & 1 deletion pkg/externalLink/ExternalLinkRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (
)

type ExternalLink struct {
tableName struct{} `sql:"external_link"`
tableName struct{} `sql:"external_link" pg:",discard_unknown_columns"`
Id int `sql:"id,pk"`
ExternalLinkMonitoringToolId int `sql:"external_link_monitoring_tool_id, notnull"`
Name string `sql:"name,notnull"`
Expand Down
3 changes: 3 additions & 0 deletions pkg/k8s/application/k8sApplicationService.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
k8s2 "github.com/devtron-labs/common-lib/utils/k8s"
k8sCommonBean "github.com/devtron-labs/common-lib/utils/k8s/commonBean"
k8sObjectUtils "github.com/devtron-labs/common-lib/utils/k8sObjectsUtil"
"github.com/devtron-labs/devtron/internal/util"

yamlUtil "github.com/devtron-labs/common-lib/utils/yaml"
"github.com/devtron-labs/devtron/api/connector"
client "github.com/devtron-labs/devtron/api/helm-app"
Expand Down Expand Up @@ -425,6 +427,7 @@ func (impl *K8sApplicationServiceImpl) validateContainerNameIfReqd(valid bool, r
func (impl *K8sApplicationServiceImpl) GetResourceInfo(ctx context.Context) (*bean3.ResourceInfo, error) {
pod, err := impl.K8sUtil.GetResourceInfoByLabelSelector(ctx, impl.aCDAuthConfig.ACDConfigMapNamespace, "app=inception")
if err != nil {
err = &util.ApiError{Code: "404", HttpStatusCode: 404, UserMessage: "error on getting resource from k8s"}
impl.logger.Errorw("error on getting resource from k8s, unable to fetch installer pod", "err", err)
return nil, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/pipeline/BuildPipelineConfigService.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"encoding/json"
"fmt"
"github.com/caarlos0/env"
"github.com/devtron-labs/common-lib/utils"
app2 "github.com/devtron-labs/devtron/internal/sql/repository/app"
"github.com/devtron-labs/devtron/internal/sql/repository/appWorkflow"
dockerRegistryRepository "github.com/devtron-labs/devtron/internal/sql/repository/dockerRegistry"
Expand Down Expand Up @@ -1236,6 +1237,7 @@ func (impl *CiPipelineConfigServiceImpl) handlePipelineCreate(request *bean.CiPa
}

if pipelineExists {
err = &utils.ApiError{Code: "400", HttpStatusCode: 400, UserMessage: "pipeline name already exist"}
impl.logger.Errorw("pipeline name already exist", "err", err, "patch cipipeline name", request.CiPipeline.Name)
return nil, fmt.Errorf(bean3.PIPELINE_NAME_ALREADY_EXISTS_ERROR)
}
Expand Down

0 comments on commit 7cff679

Please sign in to comment.