{"record":{"id":"4df8694afaf14801","repo":"kubernetes/kops","slug":"error-getting-file-status-of-q-v","errorCode":null,"errorMessage":"error getting file status of %q: %v","messagePattern":"error getting file status of %q: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/dns/hosts/hosts.go","lineNumber":116,"sourceCode":"\tfor _, record := range m.records {\n\t\tif record.Hostname == hostname {\n\t\t\tcontinue\n\t\t}\n\t\tnewRecords = append(newRecords, record)\n\t}\n\n\tm.records = newRecords\n}\n\n// UpdateHostsFileWithRecords updates /etc/hosts by applying the given mutation function.\nfunc UpdateHostsFileWithRecords(p string, mutator func(guarded []string) (*HostMap, error)) error {\n\t// For safety / sanity, we avoid concurrent updates from one process\n\thostsFileMutex.Lock()\n\tdefer hostsFileMutex.Unlock()\n\n\tstat, err := os.Stat(p)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error getting file status of %q: %v\", p, err)\n\t}\n\n\tdata, err := os.ReadFile(p)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error reading file %q: %v\", p, err)\n\t}\n\n\tvar guarded []string\n\tvar out []string\n\tinGuardBlock := false\n\tfor _, line := range strings.Split(string(data), \"\\n\") {\n\t\tk := strings.TrimSpace(line)\n\t\tif k == GUARD_BEGIN {\n\t\t\tif inGuardBlock {\n\t\t\t\tklog.Warningf(\"/etc/hosts guard-block begin seen while in guard block; will ignore\")\n\t\t\t}\n\t\t\tinGuardBlock = true\n\t\t}","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/kubernetes/kops/blob/4c8573c808a73d578c5eadc86d410646ea0b0d73/pkg/dns/hosts/hosts.go#L98-L134","documentation":"os.Stat on the hosts file path failed before any mutation is applied; typically the file does not exist, or the path is unreadable due to permissions or a missing mount in the container/host context.","triggerScenarios":"Thrown at pkg/dns/hosts/hosts.go:116 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the hosts file path (e.g. /etc/hosts) exists in this context","Check read permissions on the path","Create the file with mode 0644 first if it legitimately does not exist"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4c8573c808a73d578c5eadc86d410646ea0b0d73","analyzedAt":"2026-09-05T04:13:19.212Z","contentChangedAt":"2026-09-05T04:13:19.212Z","schemaVersion":2},"datasetVersion":"2026-09-12T07:17:12.445Z"}