apache/answer · error

read config file failed: %w

Error message

read config file failed: %w

What it means

ResetPassword wraps a failure from conf.ReadConfig(path.GetConfigFilePath()), which parses the app config file (TOML/etc.). The CLI cannot read or parse the configuration, so it cannot obtain database settings to proceed.

Source

Thrown at internal/cli/reset_password.go:74

var charset = []string{
	charsetLower,
	charsetUpper,
	charsetDigits,
	charsetSpecial,
}

type ResetPasswordOptions struct {
	Email    string
	Password string
}

func ResetPassword(ctx context.Context, dataDirPath string, opts *ResetPasswordOptions) error {
	path.FormatAllPath(dataDirPath)

	config, err := conf.ReadConfig(path.GetConfigFilePath())
	if err != nil {
		return fmt.Errorf("read config file failed: %w", err)
	}

	db, err := initDatabase(config.Data.Database.Driver, config.Data.Database.Connection)
	if err != nil {
		return fmt.Errorf("connect database failed: %w", err)
	}
	defer func() {
		_ = db.Close()
	}()

	cache, cacheCleanup, err := data.NewCache(config.Data.Cache)
	if err != nil {
		return fmt.Errorf("initialize cache failed: %w", err)
	}
	defer cacheCleanup()

	dataData, dataCleanup, err := data.NewData(db, cache)
	if err != nil {

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Verify the config file exists at path.GetConfigFilePath() (run environment init first).
  2. Check file permissions for the running user.
  3. Validate the config file syntax; re-install a fresh copy if it was hand-edited badly.

Example fix

// before
err := cli.ResetPassword(ctx, "/opt/appdata", opts)
// after
if _, err := os.Stat(filepath.Join("/opt/appdata", "config.toml")); err != nil {
    return fmt.Errorf("config file missing in data dir; run init first: %w", err)
}
err := cli.ResetPassword(ctx, "/opt/appdata", opts)
Defensive patterns

Strategy: validation

Validate before calling

cfgPath := filepath.Join(dataDirPath, "config.toml")
if _, err := os.Stat(cfgPath); err != nil {
    return fmt.Errorf("config file missing; run init: %w", err)
}

Try / catch

if err := cli.ResetPassword(ctx, dataDir, opts); err != nil {
    if strings.Contains(err.Error(), "read config file failed") {
        log.Fatalf("init environment first or fix data dir: %v", err)
    }
}

Prevention

When it happens

Trigger: ResetPassword called with a dataDirPath whose config file is missing, unreadable, or malformed — commonly because InstallConfigFile was never run in that data dir.

Common situations: Wrong --data-dir passed on the CLI, config file deleted, config edited with syntax errors, permission issues after container image changes.

Related errors


AI-assisted analysis of apache/answer@3b9f137061 (2026-09-05). Data as JSON: /api/errors/677662873ccc2597. Report an issue: GitHub.