jaegertracing/jaeger · error

cannot load config file %s: %w

Error message

cannot load config file %s: %w

What it means

TryLoadConfigFile reads the --config-file value from Viper and calls v.ReadInConfig(); any read/parse failure is wrapped as "cannot load config file %s" with the file path embedded. Viper returns errors for missing files, unsupported extensions, and invalid syntax (YAML/JSON parse errors).

Source

Thrown at cmd/internal/flags/flags.go:35

const (
	logLevel    = "log-level"
	logEncoding = "log-encoding" // json or console
	configFile  = "config-file"
)

// AddConfigFileFlag adds flags for ExternalConfFlags
func AddConfigFileFlag(flagSet *flag.FlagSet) {
	flagSet.String(configFile, "", "Configuration file in JSON, TOML, YAML, HCL, or Java properties formats (default none). See spf13/viper for precedence.")
}

// TryLoadConfigFile initializes viper with config file specified as flag
func TryLoadConfigFile(v *viper.Viper) error {
	if file := v.GetString(configFile); file != "" {
		v.SetConfigFile(file)
		err := v.ReadInConfig()
		if err != nil {
			return fmt.Errorf("cannot load config file %s: %w", file, err)
		}
	}
	return nil
}

// ParseJaegerTags parses the Jaeger tags string into a map.
func ParseJaegerTags(jaegerTags string) (map[string]string, error) {
	if jaegerTags == "" {
		return nil, nil
	}
	tagPairs := strings.Split(string(jaegerTags), ",")
	tags := make(map[string]string)
	for _, p := range tagPairs {
		kv := strings.SplitN(p, "=", 2)
		if len(kv) != 2 {
			return nil, fmt.Errorf("invalid Jaeger tag pair %q, expected key=value", p)
		}
		k, v := strings.TrimSpace(kv[0]), strings.TrimSpace(kv[1])

View on GitHub (pinned to 806f444784)

Solutions

  1. Check the path in the message exists and is readable (ls/permissions).
  2. Validate the file's YAML/JSON syntax with a linter (yamllint, jq).
  3. Confirm the extension is supported (.yaml, .yml, .json, .toml).
  4. In Kubernetes, verify the ConfigMap volume is mounted before startup.

Example fix

// before
--config-file=/etc/jaeger/config.yamln  # typo, file missing
// after
--config-file=/etc/jaeger/config.yaml
Defensive patterns

Strategy: validation

Validate before calling

path := v.GetString("config-file")
if path != "" {
    if _, err := os.Stat(path); err != nil {
        return fmt.Errorf("config file not readable: %w", err)
    }
    if err := yaml.Unmarshal; /* validate syntax */ ; err != nil {
        return err
    }
}

Try / catch

if err := TryLoadConfigFile(v); err != nil {
    var pathErr *fs.PathError
    if errors.As(err, &pathErr) { /* fix path/permissions */ }
    return fmt.Errorf("startup aborted: %w", err)
}

Prevention

When it happens

Trigger: Passing --config-file pointing to a nonexistent file, a file with an extension Viper cannot infer, unreadable permissions, or a malformed YAML/JSON document that fails Unmarshal.

Common situations: Typo in the mounted config path; ConfigMap not mounted yet at process start; YAML indentation error introduced by hand-editing; renaming the file to .yaml while it contains JSON with wrong syntax.

Related errors


AI-assisted analysis of jaegertracing/jaeger@806f444784 (2026-09-01). Data as JSON: /api/errors/4efa6b66a54f33a5. Report an issue: GitHub.