{"record":{"id":"d7dc1db80d959349","repo":"snail007/goproxy","slug":"auth-file-err-s","errorCode":null,"errorMessage":"auth-file ERR:%s","messagePattern":"auth-file ERR:(.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"services/http.go","lineNumber":174,"sourceCode":"\t\t//parent string, timeout int, InitialCap int, MaxCap int\n\t\ts.outPool = utils.NewOutPool(\n\t\t\t*s.cfg.CheckParentInterval,\n\t\t\t*s.cfg.ParentType == TYPE_TLS,\n\t\t\ts.cfg.CertBytes, s.cfg.KeyBytes,\n\t\t\t*s.cfg.Parent,\n\t\t\t*s.cfg.Timeout,\n\t\t\t*s.cfg.PoolSize,\n\t\t\t*s.cfg.PoolSize*2,\n\t\t)\n\t}\n}\nfunc (s *HTTP) InitBasicAuth() (err error) {\n\ts.basicAuth = utils.NewBasicAuth()\n\tif *s.cfg.AuthFile != \"\" {\n\t\tvar n = 0\n\t\tn, err = s.basicAuth.AddFromFile(*s.cfg.AuthFile)\n\t\tif err != nil {\n\t\t\terr = fmt.Errorf(\"auth-file ERR:%s\", err)\n\t\t\treturn\n\t\t}\n\t\tlog.Printf(\"auth data added from file %d , total:%d\", n, s.basicAuth.Total())\n\t}\n\tif len(*s.cfg.Auth) > 0 {\n\t\tn := s.basicAuth.Add(*s.cfg.Auth)\n\t\tlog.Printf(\"auth data added %d, total:%d\", n, s.basicAuth.Total())\n\t}\n\treturn\n}\nfunc (s *HTTP) IsBasicAuth() bool {\n\treturn *s.cfg.AuthFile != \"\" || len(*s.cfg.Auth) > 0\n}\nfunc (s *HTTP) IsDeadLoop(inLocalAddr string, host string) bool {\n\tinIP, inPort, err := net.SplitHostPort(inLocalAddr)\n\tif err != nil {\n\t\treturn false\n\t}","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/snail007/goproxy/blob/e6d6a821db80e7f47ee6e981a144984e1d4ddb3d/services/http.go#L156-L192","documentation":"InitBasicAuth loads HTTP basic-auth credentials for the service. When an auth file is configured it calls basicAuth.AddFromFile, and if reading/parsing that file fails, the underlying error is wrapped as \"auth-file ERR:%s\" and returned, aborting service startup via InitService.","triggerScenarios":"*cfg.AuthFile is set to a path that does not exist, is unreadable (permissions), or whose contents do not match the expected user:password line format, causing AddFromFile to return an error which gets wrapped.","commonSituations":"Wrong relative path after changing working directory (systemd/docker working dir differs); file missing in the container image; malformed lines (missing colon, whitespace, wrong charset); file mounted without read permission.","solutions":["Check the error wrapped after 'auth-file ERR:' and fix the underlying cause (missing file, bad permission, malformed line)","Use an absolute path for the auth file in the config so it is independent of the working directory","Validate each line is 'user:password' (one per line) with no stray whitespace or BOM","Alternatively configure credentials inline via the auth config option instead of a file"],"exampleFix":"// before\n// auth_file=./user.conf   (file not present in container)\n// after\n// auth_file=/etc/nps/user.conf  (absolute path, exists, chmod 600)","handlingStrategy":"validation","validationCode":"func validateAuthFile(path string) error {\n    f, err := os.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    sc := bufio.NewScanner(f)\n    for i := 1; sc.Scan(); i++ {\n        line := strings.TrimSpace(sc.Text())\n        if line == \"\" { continue }\n        if !strings.Contains(line, \":\") {\n            return fmt.Errorf(\"line %d: expected user:password\", i)\n        }\n    }\n    return sc.Err()\n}","typeGuard":null,"tryCatchPattern":"if err := svc.Init(); err != nil {\n    var authFileErr bool\n    if strings.HasPrefix(err.Error(), \"auth-file ERR:\") { authFileErr = true }\n    if authFileErr {\n        log.Fatalf(\"fix auth file config: %v\", err)\n    }\n}","preventionTips":["Use absolute paths for the auth file and mount it read-only in containers","Keep the file format strictly user:password, one per line, no BOM","Check file existence and permissions in your deployment/health script","Prefer inline auth config for tiny credential sets to avoid file issues"],"tags":["authentication","basic-auth","file-io","configuration"],"backgroundTag":"auth-file-load-failed","analyzedSha":"e6d6a821db80e7f47ee6e981a144984e1d4ddb3d","analyzedAt":"2026-09-03T15:32:42.750Z","contentChangedAt":"2026-09-03T15:32:42.750Z","schemaVersion":2},"datasetVersion":"2026-09-11T00:17:11.886Z"}