browsh-org/browsh · critical

Config file error: %s

Error message

Config file error: %s 

What it means

`loadConfig` first loads an embedded sample config (so new default fields exist) and then merges the user's own .toml over it via `viper.MergeInConfig`. Either read failing causes a panic with `Config file error: <err>`. The first panic (sample config) is effectively an internal bug; the second means the user's config file is missing, unreadable, or malformed TOML.

Source

Thrown at interfacer/src/browsh/config.go:91

}

func setDefaults() {
	// Temporary experimental configurable keybindings
	viper.SetDefault("tty.keys.next-tab", []string{"\u001c", "28", "2"})
}

func loadConfig() {
	dir := getConfigDir()
	fullPath := filepath.Join(dir, configFilename)
	slog.Info("Looking in " + fullPath + " for config.")
	viper.SetConfigType("toml")
	viper.SetConfigName(strings.Trim(configFilename, ".toml"))
	viper.AddConfigPath(dir)
	viper.AddConfigPath(".")
	setDefaults()
	// First load the sample config in case the user hasn't updated any new fields
	if err := viper.ReadConfig(bytes.NewBuffer([]byte(configSample))); err != nil {
		panic(fmt.Errorf("Config file error: %s \n", err))
	}
	// Then load the users own config file, overwriting the sample config
	if err := viper.MergeInConfig(); err != nil {
		panic(fmt.Errorf("Config file error: %s \n", err))
	}
	viper.BindPFlags(pflag.CommandLine)
}

View on GitHub (pinned to 499ef386d4)

Solutions

  1. Run the TOML through a validator/linter and fix the syntax errors reported in the panic message.
  2. Confirm the file exists and is readable at the resolved location (cwd or the configured dir) and that its name survives the `.toml`-character trimming (stick to a plain `browsh.toml`).
  3. Start with the sample config from the repo, then incrementally add your own settings.
  4. Check file permissions (`chmod u+r config.toml`) if the file exists but can't be read.

Example fix

// before (config.toml, invalid TOML)
firefox]
path = /usr/bin/firefox
// after
[firefox]
path = "/usr/bin/firefox"
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const configFile = 'browsh.toml';
if (!fs.existsSync(configFile)) throw new Error(`Config file ${configFile} not found`);
const toml = require('@iarna/toml');
toml.parse(fs.readFileSync(configFile, 'utf8')); // throws on invalid TOML

Try / catch

try {
  startBrowsh();
} catch (e) {
  if (/Config file error/.test(e.message)) {
    console.error('Fix or provide browsh config (.toml):', e.message);
  } else { throw e; }
}

Prevention

When it happens

Trigger: `Initialise` -> `loadConfig`; `viper.MergeInConfig()` fails because the config file derived from `configFilename`/the `-config` flag doesn't exist, has no read permission, or contains invalid TOML (the sample-config panic only occurs if the embedded sample itself fails to parse).

Common situations: Wrong `-config` filename (note `strings.Trim(configFilename, ".toml")` strips any leading/trailing chars in the set '.tml o', so unusual extensions/names break lookup); hand-edited TOML with syntax errors (missing quotes/brackets); unreadable permissions; running from a directory without the expected config file.

Related errors


AI-assisted analysis of browsh-org/browsh@499ef386d4 (2026-09-02). Data as JSON: /api/errors/1216aa0e5b24dca2. Report an issue: GitHub.