jaegertracing/jaeger · error
failed to initialize config: %w
Error message
failed to initialize config: %w
What it means
ExecuteAction in es-rollover first initializes the rollover Config from Viper; if cfg.InitFromViper returns an error (invalid flag values, bad env binding, failed parsing), the error is wrapped with this message and returned. It means the rollover configuration itself could not be built before any ES call was attempted.
Source
Thrown at cmd/es-rollover/app/actions.go:69
type Action interface {
Do() error
}
// ActionExecuteOptions are the options passed to the execute action function
type ActionExecuteOptions struct {
Args []string
Viper *viper.Viper
Logger *zap.Logger
}
// ActionCreatorFunction type is the function type in charge of create the action to be executed
type ActionCreatorFunction func(*esclient.Client, Config) Action
// ExecuteAction execute the action returned by the createAction function
func ExecuteAction(opts ActionExecuteOptions, createAction ActionCreatorFunction) error {
cfg := Config{}
if err := cfg.InitFromViper(opts.Viper); err != nil {
return fmt.Errorf("failed to initialize config: %w", err)
}
esClient, err := newESClient(context.Background(), opts.Args[0], &cfg, opts.Logger)
if err != nil {
return fmt.Errorf("failed to create Elasticsearch client: %w", err)
}
action := createAction(esClient, cfg)
return action.Do()
}
View on GitHub (pinned to 806f444784)
Solutions
- Inspect the wrapped cause for the exact field that failed to parse.
- Print/validate the rollover flags (ES_URL, index prefix, units, etc.) passed to the command.
- Fix the offending flag/env/config-file value and re-run.
- Check for stray environment variables overriding flags via viper AutomaticEnv.
Example fix
// before ROLLOVER_INDEX_DAYS=every-day ./es-rollover init // after — numeric/typed values only ROLLOVER_INDEX_DAYS=30 ./es-rollover init
Defensive patterns
Strategy: validation
Validate before calling
cfg := app.Config{}
if err := cfg.InitFromViper(v); err != nil {
return fmt.Errorf("invalid rollover flags: %w", err)
} Try / catch
if err := ExecuteAction(opts, createAction); err != nil {
var cfgErr *ConfigError
if errors.As(err, &cfgErr) { /* fix flag values */ }
return err
} Prevention
- Keep flag values typed correctly in manifests (numbers, bools, durations).
- Audit environment variables that viper AutomaticEnv may pick up.
- Test rollover commands with the same flags in CI before production.
When it happens
Trigger: Calling ExecuteAction with a Viper instance holding an invalid value for a rollover config field (e.g. non-numeric unit count, malformed duration, bad bool) so cfg.InitFromViper fails.
Common situations: Wrong CLI flag values in a cronjob/K8s manifest; environment variable of the wrong type shadowing a flag; typo'd flag name leaving an invalid default; config file loaded with an incompatible key type.
Related errors
- cannot load config file %s: %w
- cannot load config file: %w
- error generating mappings: %w
- no sampling strategy provider specified, expecting 'adaptive
- only one sampling strategy provider can be specified, 'adapt
AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01).
Data as JSON: /api/errors/20b06f5afbed34ae.
Report an issue: GitHub.