{"record":{"id":"bb91f941b646ff62","repo":"helm/helm","slug":"couldn-t-load-repositories-file-s-w","errorCode":null,"errorMessage":"couldn't load repositories file (%s): %w","messagePattern":"couldn't load repositories file \\((.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"pkg/repo/v1/repo.go","lineNumber":51,"sourceCode":"}\n\n// NewFile generates an empty repositories file.\n//\n// Generated and APIVersion are automatically set.\nfunc NewFile() *File {\n\treturn &File{\n\t\tAPIVersion:   APIVersionV1,\n\t\tGenerated:    time.Now(),\n\t\tRepositories: []*Entry{},\n\t}\n}\n\n// LoadFile takes a file at the given path and returns a File object\nfunc LoadFile(path string) (*File, error) {\n\tr := new(File)\n\tb, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn r, fmt.Errorf(\"couldn't load repositories file (%s): %w\", path, err)\n\t}\n\n\terr = yaml.Unmarshal(b, r)\n\treturn r, err\n}\n\n// Add adds one or more repo entries to a repo file.\nfunc (r *File) Add(re ...*Entry) {\n\tr.Repositories = append(r.Repositories, re...)\n}\n\n// Update attempts to replace one or more repo entries in a repo file. If an\n// entry with the same name doesn't exist in the repo file it will add it.\nfunc (r *File) Update(re ...*Entry) {\n\tfor _, target := range re {\n\t\tr.update(target)\n\t}\n}","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/helm/helm/blob/2a29f1770b62844b27197d2507377361d45ad7c0/pkg/repo/v1/repo.go#L33-L69","documentation":"repo.LoadFile failed to read the repositories.yaml file - os.ReadFile returned an error such as file-not-exists or permission-denied. Note the function still returns a non-nil, empty *File alongside the error, so callers must decide whether a missing file is fatal or just means no repositories are configured.","triggerScenarios":"LoadFile on a host where no repository has ever been added (repositories.yaml never created), HELM_CONFIG_HOME/XDG_CONFIG_HOME pointing to an unreadable path, or file permissions denying read access to the config file.","commonSituations":"Fresh containers or CI images that never ran `helm repo add`; misconfigured HELM_* environment variables; running as a different user than the one owning the config; cleanup scripts deleting helm config.","solutions":["Check the expected path: `helm env | grep HELM_CONFIG_HOME`, then inspect <config>/helm/repositories.yaml","Initialize it by adding any repository: `helm repo add stable https://charts.helm.sh/stable` creates the file","Fix directory/file permissions or correct the HELM_CONFIG_HOME value","In code, treat a not-exist error as an empty repo list rather than a fatal failure"],"exampleFix":"// before\nf, err := repo.LoadFile(path)\nif err != nil {\n\treturn err // fails on fresh installs with no repositories.yaml\n}\n\n// after\nf, err := repo.LoadFile(path)\nif err != nil {\n\tif os.IsNotExist(err) {\n\t\tf = repo.NewFile()\n\t} else {\n\t\treturn err\n\t}\n}","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(path); err != nil {\n\tif os.IsNotExist(err) {\n\t\treturn repo.NewFile(), nil // no repositories configured yet - not an error\n\t}\n\treturn nil, err\n}\nreturn repo.LoadFile(path)","typeGuard":null,"tryCatchPattern":"f, err := repo.LoadFile(path)\nif err != nil {\n\tif os.IsNotExist(errors.Unwrap(err)) || strings.Contains(err.Error(), \"couldn't load repositories file\") {\n\t\tf = repo.NewFile() // proceed with zero repos\n\t} else {\n\t\treturn err\n\t}\n}","preventionTips":["Stat the file before loading and treat not-exists as an empty repository set","Ensure HELM_CONFIG_HOME is set and writable in containers/CI before first use","Run one `helm repo add` during environment bootstrap so the config file exists"],"tags":["config","file","repository","environment"],"backgroundTag":null,"analyzedSha":"2a29f1770b62844b27197d2507377361d45ad7c0","analyzedAt":"2026-08-15T22:02:47.490Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}