Skip to content

fix: 500 fixes second iteration #4464

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 24 commits into from
Jan 21, 2024
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
370bfeb
FetchChartNotes return 4xx when installed app or installed app versio…
prakash100198 Dec 21, 2023
a1211e9
GetDeploymentHistory and GetInstalledAppVersion to return 4xx when in…
prakash100198 Dec 21, 2023
803b53d
fixes
prakash100198 Dec 21, 2023
9bee9f9
adding pg:",discard_unknown_columns" in tables where doesn't exist
prakash100198 Dec 22, 2023
886c20c
fix for Git Sensor response
ShashwatDadhich Dec 26, 2023
7fa9dc0
Merge branch 'main' into error-5xx-2
prakash100198 Dec 26, 2023
018d7d6
fix for inception
ShashwatDadhich Dec 27, 2023
6fa10d2
Merge branch 'error-5xx-2' into 500-fix-2.0
prakash100198 Dec 27, 2023
6cb1507
fix for k8s resource delete
ShashwatDadhich Dec 27, 2023
885e3f4
fix for pipeline already exists
ShashwatDadhich Dec 28, 2023
054f1ca
fix for pipeline already exists
ShashwatDadhich Dec 28, 2023
2d85e92
fix for pipeline already exists
ShashwatDadhich Dec 28, 2023
34388d3
fix
ShashwatDadhich Jan 4, 2024
a193029
fix
ShashwatDadhich Jan 4, 2024
b8f6d5a
fix
ShashwatDadhich Jan 4, 2024
0df52f5
fix
ShashwatDadhich Jan 4, 2024
bf70c7d
go mod version changes
prakash100198 Jan 15, 2024
61ceb03
main sync
prakash100198 Jan 15, 2024
7a68fb9
Merge branch 'main' into 500-fix-2.0
prakash100198 Jan 15, 2024
bed7ac9
merged
ShashwatDadhich Jan 18, 2024
81ced3a
Merge branch 'main' into 500-fix-2.0
prakash100198 Jan 18, 2024
0e92dab
common lib main version sync
prakash100198 Jan 18, 2024
0ac6317
Merge branch 'main' into 500-fix-2.0
prakash100198 Jan 21, 2024
072bba8
main merge
prakash100198 Jan 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ require (
github.com/davecgh/go-spew v1.1.1
github.com/deckarep/golang-set v1.8.0
github.com/devtron-labs/authenticator v0.4.33
github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5
github.com/devtron-labs/common-lib v0.0.10-0.20240118140811-762cb3b7f9a4
github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2
github.com/evanphx/json-patch v5.6.0+incompatible
github.com/ghodss/yaml v1.0.1-0.20190212211648-25d852aebe32
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@ github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4 h1:YcpmyvADG
github.com/denisenkom/go-mssqldb v0.0.0-20190707035753-2be1aa521ff4/go.mod h1:zAg7JM8CkOJ43xKXIj7eRO9kmWm/TW578qo+oDO6tuM=
github.com/devtron-labs/authenticator v0.4.33 h1:FpAV3ZgFluaRFcMwPpwxr/mwSipJ16XRvgABq3BzP5Y=
github.com/devtron-labs/authenticator v0.4.33/go.mod h1:ozNfT8WcruiSgnUbyp48WVfc41++W6xYXhKFp67lNTU=
github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5 h1:+Nh2SMzAdgBr1tgdKAlF5cN0CvTPUj1V/sI5aRUrZnE=
github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5/go.mod h1:pBThgympEjsza6GShqNNGCPBFXNDx0DGMc7ID/VHTAw=
github.com/devtron-labs/common-lib v0.0.10-0.20240118140811-762cb3b7f9a4 h1:S2ouUWhefHd3UQjP7gAfrjpqDM5qr/sfnsveQcv+aQo=
github.com/devtron-labs/common-lib v0.0.10-0.20240118140811-762cb3b7f9a4/go.mod h1:95/DizzVXu1kHap/VwEvdxwgd+BvPVYc0bJzt8yqGDU=
github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2 h1:/IEIsJTxDZ3hv8uOoCaqdWCXqcv7nCAgX9AP/v84dUY=
github.com/devtron-labs/protos v0.0.0-20230503113602-282404f70fd2/go.mod h1:l85jxWHlcSo910hdUfRycL40yGzC6glE93V1sVxVPto=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down
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 @@ -910,11 +910,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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ github.com/devtron-labs/authenticator/jwt
github.com/devtron-labs/authenticator/middleware
github.com/devtron-labs/authenticator/oidc
github.com/devtron-labs/authenticator/password
# github.com/devtron-labs/common-lib v0.0.9-0.20231226070212-c47f7a07ebf5
# github.com/devtron-labs/common-lib v0.0.10-0.20240118140811-762cb3b7f9a4
## explicit; go 1.20
github.com/devtron-labs/common-lib/blob-storage
github.com/devtron-labs/common-lib/pubsub-lib
Expand Down