owasp-amass/amass · critical

failed to load the main configuration file: %v

Error message

failed to load the main configuration file: %v

What it means

LoadSettings reads the configuration file at c.Filepath with os.ReadFile; if the read fails it loads database/engine env settings as a fallback and returns 'failed to load the main configuration file'. This means the config path resolved but the file could not be opened and read (missing, permission denied, or it is a directory).

Source

Thrown at config/config.go:273

}

// LoadSettings parses settings from an .yaml file and assigns them to the Config.
func (c *Config) LoadSettings(path string) error {
	// Determine and store the absolute path of the config file
	absolutePath, err := filepath.Abs(path)
	if err != nil {
		_ = c.LoadDatabaseEnvSettings()
		_ = c.LoadEngineEnvSettings()
		return fmt.Errorf("failed to get absolute path of the configuration file: %v", err)
	}
	c.Filepath = absolutePath

	// Open the configuration file
	data, err := os.ReadFile(c.Filepath)
	if err != nil {
		_ = c.LoadDatabaseEnvSettings()
		_ = c.LoadEngineEnvSettings()
		return fmt.Errorf("failed to load the main configuration file: %v", err)
	}

	err = yaml.Unmarshal(data, c)
	if err != nil {
		_ = c.LoadDatabaseEnvSettings()
		_ = c.LoadEngineEnvSettings()
		return fmt.Errorf("error mapping configuration settings to internal values: %v", err)
	}

	if err := c.loadSeedandScopeSettings(); err != nil {
		return err
	}

	loads := []func(cfg *Config) error{
		c.loadAlterationSettings,
		c.loadBruteForceSettings,
		c.loadDatabaseSettings,
		c.loadDataSourceSettings,

View on GitHub (pinned to 79299dce87)

Solutions

  1. Verify the path exists: `ls -l <path>`; correct typos in the config path argument.
  2. Fix permissions: `chmod +r <config>` or run as a user with access.
  3. If the path is relative, confirm the process's working directory, or pass an absolute path.
  4. As a stopgap, set the relevant DATABASE/ENGINE env vars since LoadSettings still applies env settings before failing.

Example fix

// before
err := cfg.LoadSettings("./confg.yaml") // typo
// after
err := cfg.LoadSettings("./config.yaml")
Defensive patterns

Strategy: validation

Validate before calling

func assertReadable(path string) error {
    info, err := os.Stat(path)
    if err != nil {
        return fmt.Errorf("config not accessible: %w", err)
    }
    if info.IsDir() {
        return fmt.Errorf("%s is a directory", path)
    }
    f, err := os.Open(path)
    if err != nil {
        return fmt.Errorf("config unreadable: %w", err)
    }
    return f.Close()
}

Try / catch

if err := cfg.LoadSettings(path); err != nil {
    if strings.Contains(err.Error(), "failed to load the main configuration file") {
        // check the path exists and is readable; env-based DB/engine settings were still applied
    }
    return err
}

Prevention

When it happens

Trigger: Calling LoadSettings with a path to a nonexistent file, a file the process cannot read, or a directory. Also triggered when the file was deleted between the earlier filepath.Abs and the read.

Common situations: Wrong --config path typo; running the tool as a user without read access to /etc/... config; mounting the config into a container at the wrong path; relative path intended for a different CWD.

Understand the failure class

Background: "Config file not found": what it means and how to fix it in docker-sync, Maven, Vagrant, Turborepo and other tools — this error's family across 60 libraries.

Related errors


AI-assisted analysis of owasp-amass/amass@79299dce87 (2026-09-06). Data as JSON: /api/errors/36e8aabfeb6d9c8e. Report an issue: GitHub.