apache/answer · error

read file failed: %s %s

Error message

read file failed: %s %s

What it means

NewTranslator scans the bundle directory for YAML translation files; when os.ReadFile fails on one of them it wraps the OS error as 'read file failed: <name> <err>'. It indicates an unreadable i18n bundle file (missing, permission, or path problem).

Source

Thrown at internal/base/translator/provider.go:76

	entries, err := os.ReadDir(c.BundleDir)
	if err != nil {
		return nil, err
	}

	// read the Bundle resources file from entries
	for _, file := range entries {
		// ignore directory
		if file.IsDir() {
			continue
		}
		// ignore non-YAML file
		if filepath.Ext(file.Name()) != ".yaml" && file.Name() != "i18n.yaml" {
			continue
		}
		log.Debugf("try to read file: %s", file.Name())
		buf, err := os.ReadFile(filepath.Join(c.BundleDir, file.Name()))
		if err != nil {
			return nil, fmt.Errorf("read file failed: %s %s", file.Name(), err)
		}

		// parse the backend translation
		originalTr := struct {
			Backend map[string]map[string]any `yaml:"backend"`
			UI      map[string]any            `yaml:"ui"`
			Plugin  map[string]any            `yaml:"plugin"`
		}{}
		if err = yaml.Unmarshal(buf, &originalTr); err != nil {
			return nil, err
		}
		translation := make(map[string]any, 0)
		for k, v := range originalTr.Backend {
			translation[k] = v
		}
		translation["backend"] = originalTr.Backend
		translation["ui"] = originalTr.UI
		translation["plugin"] = originalTr.Plugin

View on GitHub (pinned to 3b9f137061)

Solutions

  1. Check the file path printed in the error; verify the yaml file exists in the bundle dir (ls).
  2. Fix file permissions (chmod/chown) so the process can read the yaml.
  3. Verify the bundle dir configuration/env var points to the correct i18n directory.
  4. Rebuild/redeploy ensuring translation yaml files are packaged (check Dockerfile COPY steps).
Defensive patterns

Strategy: try-catch

Validate before calling

const p := filepath.Join(bundleDir, name)
if info, err := os.Stat(p); err != nil || info.IsDir() { return fmt.Errorf("translation file unavailable: %s", p) }

Try / catch

tr, err := translator.NewTranslator(cfg)
if err != nil {
  if strings.HasPrefix(err.Error(), "read file failed:") {
    log.Fatalf("i18n bundle unreadable: %v (check BundleDir=%s permissions)", err, cfg.BundleDir)
  }
}

Prevention

When it happens

Trigger: os.ReadFile(filepath.Join(c.BundleDir, file.Name())) failing: file deleted between listing and read, wrong permissions, BundleDir pointing to a wrong/nonexistent location, or a broken symlink.

Common situations: Docker image missing translation files, i18n directory mounted with wrong permissions, packaging (build/embed) not including yaml files, or I18N bundle dir env var pointing to the wrong path.

Understand the failure class

Background: "failed to read file", EACCES, ENOENT and "could not read <path>" errors: when a program can't read a file from disk — this error's family across 49 libraries.

Related errors


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