{"record":{"id":"d4cede8ae0c1d799","repo":"shadow1ng/fscan","slug":"parser-read-hosts-failed-w","errorCode":null,"errorMessage":"parser_read_hosts_failed: %w","messagePattern":"parser_read_hosts_failed: %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/parsers/parsers.go","lineNumber":41,"sourceCode":"- ReadLinesFromFile() - 文件读取\n- ParseUserPassFile() - 用户密码对解析\n- ParseHashFile()     - 哈希文件解析\n*/\n\n// =============================================================================\n// IP/主机解析\n// =============================================================================\n\n// ParseIP 解析各种格式的IP地址\n// 支持单个IP、IP范围、CIDR和文件输入\nfunc ParseIP(host string, filename string, nohosts ...string) ([]string, error) {\n\tvar hosts []string\n\n\t// 从文件读取主机列表\n\tif filename != \"\" {\n\t\tfileHosts, err := ReadLinesFromFile(filename)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(i18n.GetText(\"parser_read_hosts_failed\")+\": %w\", err)\n\t\t}\n\t\tfor _, h := range fileHosts {\n\t\t\tparsed, err := parseHostString(h)\n\t\t\tif err != nil {\n\t\t\t\tcontinue // 跳过无效行\n\t\t\t}\n\t\t\thosts = append(hosts, parsed...)\n\t\t}\n\t}\n\n\t// 解析主机参数\n\tif host != \"\" {\n\t\thostList, err := parseHostString(host)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(i18n.GetText(\"parser_parse_host_failed\")+\": %w\", err)\n\t\t}\n\t\thosts = append(hosts, hostList...)\n\t}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/shadow1ng/fscan/blob/95cc12e753bf43de7004e5aef42a9ffba3934303/common/parsers/parsers.go#L23-L59","documentation":"ParseIP reads target hosts from a file (the -hf flag). If ReadLinesFromFile fails to open or read the file, ParseIP wraps the error with the i18n message 'parser_read_hosts_failed'. It indicates the hosts file could not be loaded, not that any line was invalid (invalid lines are silently skipped).","triggerScenarios":"Calling ParseIP(host, filename, ...) with a filename that does not exist, is a directory, or cannot be opened due to permissions — ReadLinesFromFile returns an error and this wrapper fires.","commonSituations":"Typo in the -hf path, running fscan from a different working directory so a relative path no longer resolves, or a hosts file with restrictive permissions.","solutions":["Check the file exists at the exact path (pwd/ls) and correct the path or run from the right directory","Check file permissions (read access for the running user)","If you don't need a hosts file, pass an empty filename and provide hosts via the host argument instead"],"exampleFix":"// before\nhosts, err := parsers.ParseIP(\"\", \"./host.lst\") // file moved\n// after\nhosts, err := parsers.ParseIP(\"\", \"/etc/fscan/hosts.txt\") // absolute, existing path","handlingStrategy":"validation","validationCode":"if fi, err := os.Stat(filename); err != nil || fi.IsDir() {\n\treturn fmt.Errorf(\"hosts file unavailable: %s\", filename)\n}","typeGuard":null,"tryCatchPattern":"hosts, err := parsers.ParseIP(h, hf)\nif err != nil {\n\tvar pathErr *os.PathError\n\tif errors.As(err, &pathErr) {\n\t\tlog.Fatalf(\"cannot read hosts file %s: %v\", pathErr.Path, pathErr.Err)\n\t}\n\treturn err\n}","preventionTips":["Use absolute paths for hosts files","Stat the file before passing it to ParseIP","Ensure the scanning user has read permission on the file"],"tags":["file-io","hosts-file","wraps-error"],"backgroundTag":"file-read-failed","analyzedSha":"95cc12e753bf43de7004e5aef42a9ffba3934303","analyzedAt":"2026-09-06T17:07:30.094Z","contentChangedAt":"2026-09-06T17:07:30.094Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}