{"record":{"id":"efc7796515dc9d10","repo":"caddyserver/caddy","slug":"checking-if-default-caddyfile-exists-v","errorCode":null,"errorMessage":"checking if default Caddyfile exists: %v","messagePattern":"checking if default Caddyfile exists: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/commandfuncs.go","lineNumber":923,"sourceCode":"\n// configFileWithRespectToDefault returns the filename to use for loading the config, based\n// on whether a config file is already specified and a supported default config file exists.\nfunc configFileWithRespectToDefault(logger *zap.Logger, configFile string) (string, error) {\n\tconst defaultCaddyfile = \"Caddyfile\"\n\n\t// if no input file was specified, try a default Caddyfile if the Caddyfile adapter is plugged in\n\tif configFile == \"\" && caddyconfig.GetAdapter(\"caddyfile\") != nil {\n\t\t_, err := os.Stat(defaultCaddyfile)\n\t\tif err == nil {\n\t\t\t// default Caddyfile exists\n\t\t\tif logger != nil {\n\t\t\t\tlogger.Info(\"using adjacent Caddyfile\")\n\t\t\t}\n\t\t\treturn defaultCaddyfile, nil\n\t\t}\n\t\tif !errors.Is(err, fs.ErrNotExist) {\n\t\t\t// problem checking\n\t\t\treturn configFile, fmt.Errorf(\"checking if default Caddyfile exists: %v\", err)\n\t\t}\n\t}\n\n\t// default config file does not exist or is irrelevant\n\treturn configFile, nil\n}\n\ntype moduleInfo struct {\n\tcaddyModuleID string\n\tgoModule      *debug.Module\n\terr           error\n}\n","sourceCodeStart":905,"sourceCodeEnd":936,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/cmd/commandfuncs.go#L905-L936","documentation":"While looking for a default adjacent Caddyfile, os.Stat returned an error other than fs.ErrNotExist (e.g. permission denied on a parent directory). The existence check itself is what failed, so Caddy aborts instead of silently ignoring the default file.","triggerScenarios":"Running the CLI in a directory where a path component of ./Caddyfile cannot be traversed due to permissions, or an exotic filesystem returning an unexpected stat error.","commonSituations":"Homedir with restrictive permissions when running as a different user; containers with read-only or oddly mounted workdirs; rarely, race where the file disappears between stat calls returning something other than NotExist.","solutions":["Check directory permissions along the path to the Caddyfile","Run the CLI from a directory you can read/stat","Pass --config explicitly to bypass default-file discovery"],"exampleFix":"# before\ncaddy run   # stat ./Caddyfile fails with EACCES\n\n# after\nchmod +rx ~/workdir && caddy run --config /etc/caddy/Caddyfile","handlingStrategy":"validation","validationCode":"# Ensure the working directory is traversable before running caddy:\ntest -r ./Caddyfile || true   # any stat error other than missing will surface here first","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run the CLI from directories the user can traverse","Pass --config explicitly to skip default-file discovery"],"tags":["cli","filesystem","permissions"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}