Netflix/chaosmonkey · error
failed to parse config
Error message
failed to parse config
What it means
Fires when viper's ReadConfig cannot parse the TOML config supplied via the io.Reader to NewFromReader. It means the provided config bytes are not valid TOML (syntax error, wrong format, empty input); the wrapped viper error identifies the exact parse problem and location.
Source
Thrown at config/monkey.go:139
// Defaults returns a Monkey config that just has the default values set
// it will not load local files or remote ones
func Defaults() *Monkey {
v := &Monkey{v: viper.New()}
v.setDefaults()
return v
}
// NewFromReader returns a Monkey config which parses the initial config
// from a reader. It may load remote if configured to
// Config file must be in toml format
func NewFromReader(in io.Reader) (*Monkey, error) {
m := &Monkey{v: viper.New()}
m.setDefaults()
m.v.SetConfigType("toml")
err := m.v.ReadConfig(in)
if err != nil {
return nil, errors.Wrap(err, "failed to parse config")
}
err = m.configureRemote()
if err != nil {
return nil, err
}
return m, nil
}
// configureRemote configures viper for a remote provider if the user has
// specified one
func (m *Monkey) configureRemote() error {
provider := m.v.GetString(param.DynamicProvider)
endpoint := m.v.GetString(param.DynamicEndpoint)
path := m.v.GetString(param.DynamicPath)
View on GitHub (pinned to eaa28fb761)
Solutions
- Inspect the wrapped error for the TOML parse position
- Validate the TOML with a linter before feeding the reader
- Fix duplicate keys or invalid value types
- Ensure the reader is fully written/closed before parsing
Example fix
// before
reader := strings.NewReader("key = value") // missing quotes
m, err := config.NewFromReader(reader)
// after
reader := strings.NewReader("key = \"value\"")
m, err := config.NewFromReader(reader) Defensive patterns
Strategy: validation
Validate before calling
var probe interface{}
if err := toml.Unmarshal([]byte(tomlBytes), &probe); err != nil {
return fmt.Errorf("invalid TOML before parsing: %w", err)
}
m, err := config.NewFromReader(bytes.NewReader(tomlBytes)) Try / catch
m, err := config.NewFromReader(r)
if err != nil {
log.Printf("config parse failed: %v", errors.Unwrap(err))
return err
} Prevention
- Validate generated TOML before feeding the reader
- Avoid duplicate keys
- Use a TOML library/linter in tests for fixtures
- Ensure the reader content is complete before parsing
When it happens
Trigger: Constructing a Monkey from a reader whose content is not valid TOML (bad syntax, duplicate keys, type mismatches).
Common situations: Programmatically generated config with formatting bugs, embedded config template with a typo, hand-written test fixtures.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to read config file
- failed viper.AddRemoteProvider(provider="%s", endpoint="%s",
- FATAL: no spinnaker endpoint specified in config
- could not parse spinnaker apps list from %s: body: "%s": %v
- failed to populate schedule: %v
AI-assisted analysis of Netflix/chaosmonkey@eaa28fb761 (2026-09-03).
Data as JSON: /api/errors/62b9ef0f7c07958e.
Report an issue: GitHub.