Skip to content

Commit

Permalink
fix: invalid error handling (#10384) (#10385)
Browse files Browse the repository at this point in the history
os.IsNotExist only supports errors returned by the os package

Signed-off-by: mikutas <[email protected]>

Signed-off-by: mikutas <[email protected]>
  • Loading branch information
mikutas authored Sep 6, 2022
1 parent 13af7e2 commit aa3fe62
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ import (
"github.com/argoproj/argo-cd/v2/util/dex"
dexutil "github.com/argoproj/argo-cd/v2/util/dex"
"github.com/argoproj/argo-cd/v2/util/env"
"github.com/argoproj/argo-cd/v2/util/errors"
errorsutil "github.com/argoproj/argo-cd/v2/util/errors"
grpc_util "github.com/argoproj/argo-cd/v2/util/grpc"
"github.com/argoproj/argo-cd/v2/util/healthz"
httputil "github.com/argoproj/argo-cd/v2/util/http"
Expand All @@ -118,6 +118,7 @@ import (
"github.com/argoproj/argo-cd/v2/util/swagger"
tlsutil "github.com/argoproj/argo-cd/v2/util/tls"
"github.com/argoproj/argo-cd/v2/util/webhook"
"github.com/pkg/errors"
)

const maxConcurrentLoginRequestsCountEnv = "ARGOCD_MAX_CONCURRENT_LOGIN_REQUESTS_COUNT"
Expand Down Expand Up @@ -237,9 +238,9 @@ func initializeDefaultProject(opts ArgoCDServerOpts) error {
func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer {
settingsMgr := settings_util.NewSettingsManager(ctx, opts.KubeClientset, opts.Namespace)
settings, err := settingsMgr.InitializeSettings(opts.Insecure)
errors.CheckError(err)
errorsutil.CheckError(err)
err = initializeDefaultProject(opts)
errors.CheckError(err)
errorsutil.CheckError(err)

appInformerNs := opts.Namespace
if len(opts.ApplicationNamespaces) > 0 {
Expand All @@ -259,7 +260,7 @@ func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer {
enf := rbac.NewEnforcer(opts.KubeClientset, opts.Namespace, common.ArgoCDRBACConfigMapName, nil)
enf.EnableEnforce(!opts.DisableAuth)
err = enf.SetBuiltinPolicy(assets.BuiltinPolicyCSV)
errors.CheckError(err)
errorsutil.CheckError(err)
enf.EnableLog(os.Getenv(common.EnvVarRBACDebug) == "1")

policyEnf := rbacpolicy.NewRBACPolicyEnforcer(enf, projLister)
Expand All @@ -271,7 +272,7 @@ func NewServer(ctx context.Context, opts ArgoCDServerOpts) *ArgoCDServer {
}

argocdService, err := service.NewArgoCDService(opts.KubeClientset, opts.Namespace, opts.RepoClientset)
errors.CheckError(err)
errorsutil.CheckError(err)

secretInformer := k8s.NewSecretInformer(opts.KubeClientset, opts.Namespace, "argocd-notifications-secret")
configMapInformer := k8s.NewConfigMapInformer(opts.KubeClientset, opts.Namespace, "argocd-notifications-cm")
Expand Down Expand Up @@ -542,7 +543,7 @@ func (a *ArgoCDServer) watchSettings() {
prevURL := a.settings.URL
prevOIDCConfig := a.settings.OIDCConfig()
prevDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings, a.DexTLSConfig == nil || a.DexTLSConfig.DisableTLS)
errors.CheckError(err)
errorsutil.CheckError(err)
prevGitHubSecret := a.settings.WebhookGitHubSecret
prevGitLabSecret := a.settings.WebhookGitLabSecret
prevBitbucketUUID := a.settings.WebhookBitbucketUUID
Expand All @@ -557,7 +558,7 @@ func (a *ArgoCDServer) watchSettings() {
newSettings := <-updateCh
a.settings = newSettings
newDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings, a.DexTLSConfig == nil || a.DexTLSConfig.DisableTLS)
errors.CheckError(err)
errorsutil.CheckError(err)
if string(newDexCfgBytes) != string(prevDexCfgBytes) {
log.Infof("dex config modified. restarting")
break
Expand Down Expand Up @@ -621,7 +622,7 @@ func (a *ArgoCDServer) rbacPolicyLoader(ctx context.Context) {
a.policyEnforcer.SetScopes(scopes)
return nil
})
errors.CheckError(err)
errorsutil.CheckError(err)
}

func (a *ArgoCDServer) useTLS() bool {
Expand Down Expand Up @@ -750,7 +751,7 @@ func (a *ArgoCDServer) newGRPCServer() (*grpc.Server, application.AppResourceTre
// Register reflection service on gRPC server.
reflection.Register(grpcS)
grpc_prometheus.Register(grpcS)
errors.CheckError(projectService.NormalizeProjs())
errorsutil.CheckError(projectService.NormalizeProjs())
return grpcS, appResourceTreeFn
}

Expand Down Expand Up @@ -960,7 +961,7 @@ func (a *ArgoCDServer) serveExtensions(extensionsSharedPath string, w http.Respo
return nil
})

if err != nil && !os.IsNotExist(err) {
if err != nil && !errors.Is(err, fs.ErrNotExist) {
log.Errorf("Failed to walk extensions directory: %v", err)
http.Error(w, "Internal error", http.StatusInternalServerError)
return
Expand All @@ -976,7 +977,7 @@ func (a *ArgoCDServer) registerDexHandlers(mux *http.ServeMux) {
var err error
mux.HandleFunc(common.DexAPIEndpoint+"/", dexutil.NewDexHTTPReverseProxy(a.DexServerAddr, a.BaseHRef, a.DexTLSConfig))
a.ssoClientApp, err = oidc.NewClientApp(a.settings, a.DexServerAddr, a.DexTLSConfig, a.BaseHRef)
errors.CheckError(err)
errorsutil.CheckError(err)
mux.HandleFunc(common.LoginEndpoint, a.ssoClientApp.HandleLogin)
mux.HandleFunc(common.CallbackEndpoint, a.ssoClientApp.HandleCallback)
}
Expand Down

0 comments on commit aa3fe62

Please sign in to comment.