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 <23391543+mikutas@users.noreply.github.com>

Signed-off-by: mikutas <23391543+mikutas@users.noreply.github.com>
  • Loading branch information
mikutas authored and crenshaw-dev committed Sep 6, 2022
1 parent 3d9e9f2 commit 7db5c5c
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,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 @@ -112,6 +112,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 @@ -226,9 +227,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)

factory := appinformer.NewSharedInformerFactoryWithOptions(opts.AppClientset, 0, appinformer.WithNamespace(opts.Namespace), appinformer.WithTweakListOptions(func(options *metav1.ListOptions) {}))
projInformer := factory.Argoproj().V1alpha1().AppProjects().Informer()
Expand All @@ -242,7 +243,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 Down Expand Up @@ -511,7 +512,7 @@ func (a *ArgoCDServer) watchSettings() {
prevURL := a.settings.URL
prevOIDCConfig := a.settings.OIDCConfig()
prevDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings)
errors.CheckError(err)
errorsutil.CheckError(err)
prevGitHubSecret := a.settings.WebhookGitHubSecret
prevGitLabSecret := a.settings.WebhookGitLabSecret
prevBitbucketUUID := a.settings.WebhookBitbucketUUID
Expand All @@ -526,7 +527,7 @@ func (a *ArgoCDServer) watchSettings() {
newSettings := <-updateCh
a.settings = newSettings
newDexCfgBytes, err := dex.GenerateDexConfigYAML(a.settings)
errors.CheckError(err)
errorsutil.CheckError(err)
if string(newDexCfgBytes) != string(prevDexCfgBytes) {
log.Infof("dex config modified. restarting")
break
Expand Down Expand Up @@ -590,7 +591,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 @@ -715,7 +716,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 @@ -924,7 +925,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 @@ -944,7 +945,7 @@ func (a *ArgoCDServer) registerDexHandlers(mux *http.ServeMux) {
tlsConfig.InsecureSkipVerify = true
}
a.ssoClientApp, err = oidc.NewClientApp(a.settings, a.DexServerAddr, 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 7db5c5c

Please sign in to comment.