Skip to content
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

Add additional error messages for better debugging #95

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
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
22 changes: 11 additions & 11 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,47 +116,47 @@ func ReadConfig(getEnv GetEnv) (*Config, error) {

ids, err := getServiceIDs(getEnv)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get service ids env variable: %w", err)
}
cfg.ServiceIDs = ids

rt, err := getTimeout(getEnv, EnvHTTPReadTimeout)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get read timeouts env variable: %w", err)
}
cfg.ReadTimeout = rt

wt, err := getTimeout(getEnv, EnvHTTPWriteTimeout)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get write timeouts env variable: %w", err)
}
cfg.WriteTimeout = wt

bytes, err := getHTTPMaxHeaderBytes(getEnv)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get max header bytes env variable: %w", err)
}
cfg.MaxHeaderBytes = bytes

err = loadJWTSigningKeys(getEnv, cfg.JWKeyRegister)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to load JWT signing keys: %w", err)
}

err = ensureRequiredSettings(cfg)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to ensure required settings: %w", err)
}

enableMetrics, err := getEnableMetrics(getEnv)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get metrics enabled env variable: %w", err)
}
cfg.EnableMetrics = enableMetrics

metricsDomain, err := getMetricsDomain(getEnv, cfg.EnableMetrics)
if err != nil {
return nil, err
return nil, fmt.Errorf("unable to get enable metrics domain env variable: %w", err)
}
cfg.MetricsDomain = metricsDomain

Expand Down Expand Up @@ -259,10 +259,10 @@ func getMetricsDomain(GetEnv GetEnv, enableMetrics bool) (string, error) {
func loadJWTSigningKeys(getEnv GetEnv, keys *jwt.KeyRegister) error {
err := loadKeysFromPath(getEnv, keys, EnvJWTKeyJWKURL, loadJWK)
if err != nil {
return err
return fmt.Errorf("unable to load keys from '%s': %w", EnvJWTKeyJWKURL, err)
}
err = loadKeysFromPath(getEnv, keys, EnvJWTKeyPEMURL, loadPEM)
return err
return fmt.Errorf("unable to load keys from '%s': %w", EnvJWTKeyPEMURL, err)
}

func loadKeysFromPath(getEnv GetEnv, keys *jwt.KeyRegister, envVarName string, loadFunc keyLoadingFun) error {
Expand All @@ -278,7 +278,7 @@ func loadKeysFromPath(getEnv GetEnv, keys *jwt.KeyRegister, envVarName string, l

_, err = loadFunc(keys, content)
if err != nil {
return err
return fmt.Errorf("unable to load func with content: %s: %w", string(content[:]), err)
}
return nil
}
Expand Down
Loading