{"record":{"id":"cd057ecab19aa919","repo":"thanos-io/thanos","slug":"could-not-load-test-content-s","errorCode":null,"errorMessage":"could not load test content: %s","messagePattern":"could not load test content: (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/extkingpin/path_content_reloader.go","lineNumber":130,"sourceCode":"\tdefer t.contentMtx.Unlock()\n\n\tc := make([]byte, 0, len(t.content))\n\tc = append(c, t.content...)\n\n\treturn c, nil\n}\n\n// Path returns the path to the file that contains the content.\nfunc (t *staticPathContent) Path() string {\n\treturn t.path\n}\n\n// NewStaticPathContent creates a new content that can be used to serve a static configuration. It copies the\n// configuration from `fromPath` into `destPath` to avoid confusion with file watchers.\nfunc NewStaticPathContent(fromPath string) (*staticPathContent, error) {\n\tcontent, err := os.ReadFile(fromPath)\n\tif err != nil {\n\t\treturn nil, errors.Wrapf(err, \"could not load test content: %s\", fromPath)\n\t}\n\treturn &staticPathContent{content: content, path: fromPath}, nil\n}\n\n// Rewrite rewrites the file backing this staticPathContent and swaps the local content cache. The file writing\n// is needed to trigger the file system monitor.\nfunc (t *staticPathContent) Rewrite(newContent []byte) error {\n\tt.contentMtx.Lock()\n\tdefer t.contentMtx.Unlock()\n\n\tt.content = newContent\n\t// Write the file to ensure possible file watcher reloaders get triggered.\n\treturn os.WriteFile(t.path, newContent, 0666)\n}\n","sourceCodeStart":112,"sourceCodeEnd":145,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/extkingpin/path_content_reloader.go#L112-L145","documentation":"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>'.","triggerScenarios":"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.","commonSituations":"Tests pointing at a config path relative to the wrong working directory; fixtures not generated before the test runs; typos in the fixture filename.","solutions":["Verify fromPath exists and is a regular file (os.Stat before calling).","Fix the relative path or convert it to an absolute path rooted at the test's directory.","Check file permissions so the test process user can read the file."],"exampleFix":"// before\ncontent, err := NewStaticPathContent(\"configs/ruler.yaml\") // relative to wrong cwd\n// after\ncontent, err := NewStaticPathContent(filepath.Join(\"testdata\", \"ruler.yaml\"))","handlingStrategy":"validation","validationCode":"info, err := os.Stat(fromPath)\nif err != nil || info.IsDir() { return fmt.Errorf(\"fixture %s missing or not a file\", fromPath) }","typeGuard":null,"tryCatchPattern":"content, err := NewStaticPathContent(p)\nif err != nil { t.Fatalf(\"fixture setup failed: %v\", err) }","preventionTips":["Generate test fixtures in TestMain before use","Use paths relative to the test file, not cwd","Verify fixture existence with t.Helper setup functions"],"tags":["filesystem","file-not-found","testing"],"backgroundTag":"file-not-found","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}