golangci/golangci-lint · error

can't get config directory

Error message

can't get config directory

What it means

parseConfig computes the directory of the resolved config file with filepath.Abs(filepath.Dir(usedConfigFile)) so relative paths inside the config resolve against the config's location. If converting that directory to an absolute path fails, this error is returned and config parsing aborts.

Source

Thrown at pkg/config/base_loader.go:210

		return nil
	}

	if usedConfigFile == os.Stdin.Name() {
		usedConfigFile = ""
		l.log.Infof("Reading config file stdin")
	} else {
		var err error
		usedConfigFile, err = fsutils.ShortestRelPath(usedConfigFile, "")
		if err != nil {
			l.log.Warnf("Can't pretty print config file path: %v", err)
		}

		l.log.Infof("Used config file %s", usedConfigFile)
	}

	usedConfigDir, err := filepath.Abs(filepath.Dir(usedConfigFile))
	if err != nil {
		return errors.New("can't get config directory")
	}

	l.cfg.SetConfigDir(usedConfigDir)

	return nil
}

func customDecoderHook() viper.DecoderConfigOption {
	return viper.DecodeHook(DecodeHookFunc())
}

func DecodeHookFunc() mapstructure.DecodeHookFunc {
	return mapstructure.ComposeDecodeHookFunc(
		// Default hooks (https://github.com/spf13/viper/blob/518241257478c557633ab36e474dfcaeb9a3c623/viper.go#L135-L138).
		mapstructure.StringToTimeDurationHookFunc(),
		mapstructure.StringToSliceHookFunc(","),

		// Needed for forbidigo, and output.formats.

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Run golangci-lint from a valid, existing working directory.
  2. Pass a fully absolute --config path so its directory resolves cleanly.
  3. Verify the config file actually exists at the resolved location before invoking the loader.

Example fix

// before
cd /tmp/deleted-dir && golangci-lint run --config ../.golangci.yml

// after
cd /path/to/project && golangci-lint run --config /path/to/project/.golangci.yml
Defensive patterns

Strategy: validation

Validate before calling

const fs = require('fs');
const path = require('path');
const dir = path.dirname(path.resolve(configPath));
if (!fs.existsSync(dir)) throw new Error(`Config directory does not resolve: ${dir}`);

Prevention

When it happens

Trigger: filepath.Abs failing for the directory of the used config file — typically a path resolution error on an unusual/invalid working directory or file path.

Common situations: Running with a deleted or inaccessible current working directory; exotic filesystem setups where filepath.Abs cannot resolve the relative dir.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/8b49403903f5d227. Report an issue: GitHub.