thanos-io/thanos · error

could not load test content

Error message

could not load test content: %s

What it means

NewStaticPathContent reads the file at fromPath to snapshot configuration content for testing/rewriting. If os.ReadFile cannot open or read the file (missing, permissions, is-a-directory), the error is wrapped as 'could not load test content: <path>'.

Solutions

  1. Verify fromPath exists and is a regular file (os.Stat before calling).
  2. Fix the relative path or convert it to an absolute path rooted at the test's directory.
  3. Check file permissions so the test process user can read the file.

Example fix

// before
content, err := NewStaticPathContent("configs/ruler.yaml") // relative to wrong cwd
// after
content, err := NewStaticPathContent(filepath.Join("testdata", "ruler.yaml"))
Defensive patterns

Strategy: validation

Validate before calling

info, err := os.Stat(fromPath)
if err != nil || info.IsDir() { return fmt.Errorf("fixture %s missing or not a file", fromPath) }

Try / catch

content, err := NewStaticPathContent(p)
if err != nil { t.Fatalf("fixture setup failed: %v", err) }

Prevention

When it happens

Trigger: Calling NewStaticPathContent with a fromPath that does not exist, is unreadable by the process user, or is a directory; used in TestLimiter_StartConfigReloader and TestLimiter_CanReload setups.

Common situations: Tests pointing at a config path relative to the wrong working directory; fixtures not generated before the test runs; typos in the fixture filename.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of thanos-io/thanos@35b8b99117 (2026-09-07). Data as JSON: /api/errors/cd057ecab19aa919. Report an issue: GitHub.

Appendix: source

Thrown at pkg/extkingpin/path_content_reloader.go:130

	defer t.contentMtx.Unlock()

	c := make([]byte, 0, len(t.content))
	c = append(c, t.content...)

	return c, nil
}

// Path returns the path to the file that contains the content.
func (t *staticPathContent) Path() string {
	return t.path
}

// NewStaticPathContent creates a new content that can be used to serve a static configuration. It copies the
// configuration from `fromPath` into `destPath` to avoid confusion with file watchers.
func NewStaticPathContent(fromPath string) (*staticPathContent, error) {
	content, err := os.ReadFile(fromPath)
	if err != nil {
		return nil, errors.Wrapf(err, "could not load test content: %s", fromPath)
	}
	return &staticPathContent{content: content, path: fromPath}, nil
}

// Rewrite rewrites the file backing this staticPathContent and swaps the local content cache. The file writing
// is needed to trigger the file system monitor.
func (t *staticPathContent) Rewrite(newContent []byte) error {
	t.contentMtx.Lock()
	defer t.contentMtx.Unlock()

	t.content = newContent
	// Write the file to ensure possible file watcher reloaders get triggered.
	return os.WriteFile(t.path, newContent, 0666)
}

View on GitHub (pinned to 35b8b99117)