{"record":{"id":"b987e40ba612cc61","repo":"fatedier/frp","slug":"failed-to-create-directory-w","errorCode":null,"errorMessage":"failed to create directory: %w","messagePattern":"failed to create directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/config/source/store.go","lineNumber":145,"sourceCode":"\t\tProxies:  make([]v1.TypedProxyConfig, 0, len(s.proxies)),\n\t\tVisitors: make([]v1.TypedVisitorConfig, 0, len(s.visitors)),\n\t}\n\n\tfor _, p := range s.proxies {\n\t\tstored.Proxies = append(stored.Proxies, v1.TypedProxyConfig{ProxyConfigurer: p})\n\t}\n\tfor _, v := range s.visitors {\n\t\tstored.Visitors = append(stored.Visitors, v1.TypedVisitorConfig{VisitorConfigurer: v})\n\t}\n\n\tdata, err := jsonx.MarshalIndent(stored, \"\", \"  \")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to marshal JSON: %w\", err)\n\t}\n\n\tdir := filepath.Dir(s.config.Path)\n\tif err := os.MkdirAll(dir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"failed to create directory: %w\", err)\n\t}\n\n\ttmpPath := s.config.Path + \".tmp\"\n\n\tf, err := os.OpenFile(tmpPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0o600)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create temp file: %w\", err)\n\t}\n\n\tif _, err := f.Write(data); err != nil {\n\t\tf.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"failed to write temp file: %w\", err)\n\t}\n\n\tif err := f.Sync(); err != nil {\n\t\tf.Close()\n\t\tos.Remove(tmpPath)","sourceCodeStart":127,"sourceCodeEnd":163,"githubUrl":"https://github.com/fatedier/frp/blob/6c8a8d0a97d03b44e9528d30b30c70cb9d61b405/pkg/config/source/store.go#L127-L163","documentation":"saveToFileUnlocked failed to create the parent directory of the store path via os.MkdirAll before writing the temp file. The library expects to be able to create every missing directory component of filepath.Dir(Path).","triggerScenarios":"Path like /var/lib/frpc/store.json where /var/lib/frpc (or any parent) cannot be created because of EACCES/EPERM; a parent component already exists as a regular FILE (MkdirAll then fails with ENOTDIR); read-only root filesystem in a container.","commonSituations":"Running in a minimal container where /var/lib is root-owned and the process runs non-root; typo like Path=/var/lib/frpc.json/dir/store.json where a file occupies an intermediate name; Docker with read-only volumes.","solutions":["Check the directory chain: namei -l <path> shows permissions per component and where it fails","Pre-create the directory with correct ownership: mkdir -p <dir> && chown <user> <dir>","Remove/rename any regular file that occupies a needed directory component","Move the store to a writable location (e.g. $HOME/.frp/store.json or an emptyDir in k8s) if the FS is read-only"],"exampleFix":"# before\nPath: /var/lib/frpc/store.json   # /var/lib/frpc missing, process non-root\n\n# after\nsudo mkdir -p /var/lib/frpc && sudo chown $USER /var/lib/frpc\n# or use a writable path\nPath: /home/user/.frp/store.json","handlingStrategy":"validation","validationCode":"func ensureStoreDir(path string) error {\n\tdir := filepath.Dir(path)\n\tif err := os.MkdirAll(dir, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"cannot create store dir %s: %w\", dir, err)\n\t}\n\tif err := unix.Access(dir, unix.W_OK); err != nil { // or os.WriteFile probe\n\t\treturn fmt.Errorf(\"no write access to %s\", dir)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pre-create the store directory in your deployment (systemd unit, Dockerfile, k8s manifest) with the right owner","Never let a regular file occupy any component of the store directory path","In containers, mount a writable volume at the store directory instead of writing to the image"],"tags":["filesystem","permissions","directory","container","go"],"backgroundTag":null,"analyzedSha":"6c8a8d0a97d03b44e9528d30b30c70cb9d61b405","analyzedAt":"2026-08-15T06:53:27.215Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}