{"record":{"id":"9de06604a70635c0","repo":"owasp-amass/amass","slug":"failed-to-open-resolvers-file-w","errorCode":null,"errorMessage":"failed to open resolvers file: %w","messagePattern":"failed to open resolvers file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"config/resolvers.go","lineNumber":226,"sourceCode":"\n\tif len(resolverIPs) == 0 {\n\t\treturn errors.New(\"no valid resolvers were found\")\n\t}\n\n\tc.Resolvers = resolverIPs\n\n\treturn nil\n}\n\nfunc (c *Config) loadResolversFromFile(path string) ([]string, error) {\n\tabsPath, err := filepath.Abs(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to get absolute path: %v\", err)\n\t}\n\n\tdata, err := os.ReadFile(absPath)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to open resolvers file: %w\", err)\n\t}\n\n\t// Split the file data by newlines to get the IP addresses.\n\tlines := strings.Split(string(data), \"\\n\")\n\n\tvar resolvers []string\n\tfor _, line := range lines {\n\t\tline = strings.TrimSpace(line)\n\t\t// Skip empty lines.\n\t\tif line == \"\" {\n\t\t\tcontinue\n\t\t}\n\n\t\t// Check if each line in the file is a valid IP address.\n\t\tip := net.ParseIP(line)\n\t\tif ip == nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid IP address in resolvers file: %s\", line)\n\t\t}","sourceCodeStart":208,"sourceCodeEnd":244,"githubUrl":"https://github.com/owasp-amass/amass/blob/79299dce87b0085db0f2f4ef3e9c52cccb49f514/config/resolvers.go#L208-L244","documentation":"loadResolversFromFile reads a text file of newline-separated resolver IPs and wraps any os.ReadFile failure with this message. It is thrown when the resolvers file cannot be opened/read (missing file, bad permissions, or a path error). The underlying OS error is preserved via %w so it can be inspected with errors.Is/As.","triggerScenarios":"Config-loadResolversFromFile is called with a path that does not exist, points to a directory, or is unreadable (permission denied); loadResolverSettings passes the user-supplied resolvers file path from settings.","commonSituations":"Typo in the resolvers file path in the amass config; file deleted or moved after config was written; running in a container where the file was not mounted; insufficient read permissions on the file.","solutions":["Verify the resolvers file exists at the configured path (ls the path, check for typos)","Fix file permissions so the process user can read it (chmod/chown)","If the path is relative, confirm the working directory or switch to an absolute path","Inspect the wrapped %w error (os.IsNotExist vs permission) to confirm which OS-level cause applies"],"exampleFix":"// before\ncfg.LoadResolversFromFile(\"/etc/amass/reslover.txt\") // typo\n// after\ncfg.LoadResolversFromFile(\"/etc/amass/resolvers.txt\")","handlingStrategy":"try-catch","validationCode":"if _, err := os.Stat(path); err != nil { return fmt.Errorf(\"resolvers file not accessible: %w\", err) }","typeGuard":"func fileReadable(path string) bool { f, err := os.Open(path); if err != nil { return false }; f.Close(); return true }","tryCatchPattern":"res, err := loadResolversFromFile(p)\nif err != nil {\n    var perr *fs.PathError\n    if errors.As(err, &perr) && os.IsNotExist(perr) { /* fix path */ }\n    return err\n}","preventionTips":["Use absolute paths for the resolvers file","os.Stat the path before config load","Mount/copy the file into containers","Keep config files under version control to avoid drift"],"tags":["config","file-io","resolvers"],"backgroundTag":"file-read-failed","analyzedSha":"79299dce87b0085db0f2f4ef3e9c52cccb49f514","analyzedAt":"2026-09-06T08:22:48.198Z","contentChangedAt":"2026-09-06T08:22:48.198Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}