You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
With this commit 7dd23e5#diff-7d1c2a3334601b6c1958aae0a594cba8R240 , it looks lie behaviour for loading slices changed and now if a slice has 0 length in the config file then it is attempted to be loaded from the environment variables. What happens is that if the slice is made up of structs then a new struct is initialised and them attempted to be validate and this will lead to failure if the struct as any required elements which are not set in the environment.
For example, I have a configuration file made up of the below Cfg struct:
type Cfg struct {
DataDir string `required:"true" yaml:"data_dir" json:"data_dir"`
Email []ConfigNotificationEmail `yaml:"email,omitempty" json:"email,omitempty"`
}
type ConfigNotificationEmail struct {
Server string `required:"true" yaml:"server" json:"server"`
User string `yaml:"user,omitempty" json:"user,omitempty"`
}
Loading a yaml file into the Cfg struct will now fail because the Email array which is defined as optional (omitempty) and which is made up of elements of type ConfigNotificationEmail fails because the Server element is not defined; the actual error is:
Server is required, but blank
I don't have in my configuration file any definition for a email entry but because now the env vars are looked up and during validation an empty struct of type ConfigNotificationEmail is created and then attempted to be validated, it then leads to failing to load the whole configuration.
Before the mentioned patch was applied, this was not an issue.
P.S. If I do add an email entry in my .yaml config file and this entry has the server key then things work as expected. The problem appears only when there is no email entry.
The text was updated successfully, but these errors were encountered:
Hello,
With this commit 7dd23e5#diff-7d1c2a3334601b6c1958aae0a594cba8R240 , it looks lie behaviour for loading slices changed and now if a slice has 0 length in the config file then it is attempted to be loaded from the environment variables. What happens is that if the slice is made up of structs then a new struct is initialised and them attempted to be validate and this will lead to failure if the struct as any required elements which are not set in the environment.
For example, I have a configuration file made up of the below
Cfg
struct:Loading a yaml file into the
Cfg
struct will now fail because theEmail
array which is defined as optional (omitempty
) and which is made up of elements of typeConfigNotificationEmail
fails because theServer
element is not defined; the actual error is:I don't have in my configuration file any definition for a
email
entry but because now the env vars are looked up and during validation an empty struct of typeConfigNotificationEmail
is created and then attempted to be validated, it then leads to failing to load the whole configuration.Before the mentioned patch was applied, this was not an issue.
P.S. If I do add an
email
entry in my .yaml config file and this entry has theserver
key then things work as expected. The problem appears only when there is noemail
entry.The text was updated successfully, but these errors were encountered: