config: Handle errors better

This commit is contained in:
Tom Wiesing 2022-11-23 15:27:58 +01:00
parent 8997f54a8c
commit 55d5c9c529
No known key found for this signature in database
4 changed files with 28 additions and 10 deletions

View file

@ -69,6 +69,10 @@ GRAPHDB_ADMIN_PASSWORD=${GRAPHDB_ADMIN_PASSWORD}
MYSQL_ADMIN_USER=${MYSQL_ADMIN_USER}
MYSQL_ADMIN_PASSWORD=${MYSQL_ADMIN_PASSWORD}
# The admin user and password required to access the keycloak server and api
KEYCLOAK_ADMIN_USER=${KEYCLOAK_ADMIN_USER}
KEYCLOAK_ADMIN_PASSWORD=${KEYCLOAK_ADMIN_PASSWORD}
# The admin user and password required to access the /dis/ server and api
DIS_ADMIN_USER=${DIS_ADMIN_USER}
DIS_ADMIN_PASSWORD=${DIS_ADMIN_PASSWORD}

View file

@ -7,6 +7,7 @@ import (
"github.com/FAU-CDI/wisski-distillery/pkg/environment"
"github.com/FAU-CDI/wisski-distillery/pkg/envreader"
"github.com/FAU-CDI/wisski-distillery/pkg/stringparser"
"github.com/pkg/errors"
)
// Unmarshal updates this configuration from the provided [io.Reader].
@ -45,15 +46,14 @@ func (config *Config) Unmarshal(env environment.Environment, src io.Reader) erro
// read the value with a default
value, ok := values[tEnv]
if !ok || value == "" {
if tDefault == "" {
continue
if tDefault != "" {
value = tDefault
}
value = tDefault
}
// parse the value!
if err := stringparser.Parse(env, tParser, value, vField); err != nil {
return err
return errors.Errorf("Config.Unmarshal: Setting %q, Parser %q: %s", tEnv, tParser, err)
}
}