{"record":{"id":"9880f90d05084922","repo":"router-for-me/CLIProxyAPI","slug":"failed-to-create-directory-v-9880f9","errorCode":null,"errorMessage":"failed to create directory: %v","messagePattern":"failed to create directory: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/kimi/token.go","lineNumber":88,"sourceCode":"\t// UserCode is the code the user must enter at the verification URI.\n\tUserCode string `json:\"user_code\"`\n\t// VerificationURI is the URL where the user should enter the code.\n\tVerificationURI string `json:\"verification_uri,omitempty\"`\n\t// VerificationURIComplete is the URL with the code pre-filled.\n\tVerificationURIComplete string `json:\"verification_uri_complete\"`\n\t// ExpiresIn is the number of seconds until the device code expires.\n\tExpiresIn int `json:\"expires_in\"`\n\t// Interval is the minimum number of seconds to wait between polling requests.\n\tInterval int `json:\"interval\"`\n}\n\n// SaveTokenToFile serializes the Kimi token storage to a JSON file.\nfunc (ts *KimiTokenStorage) SaveTokenToFile(authFilePath string) error {\n\tmisc.LogSavingCredentials(authFilePath)\n\tts.Type = \"kimi\"\n\n\tif err := os.MkdirAll(filepath.Dir(authFilePath), 0700); err != nil {\n\t\treturn fmt.Errorf(\"failed to create directory: %v\", err)\n\t}\n\n\t// Merge metadata using helper\n\tdata, errMerge := misc.MergeMetadata(ts, ts.Metadata)\n\tif errMerge != nil {\n\t\treturn fmt.Errorf(\"failed to merge metadata: %w\", errMerge)\n\t}\n\n\tf, err := os.Create(authFilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create token file: %w\", err)\n\t}\n\tdefer func() {\n\t\tif errClose := f.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"kimi token storage: close token file error: %v\", errClose)\n\t\t}\n\t}()\n","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/kimi/token.go#L70-L106","documentation":"Returned by KimiTokenStorage.SaveTokenToFile when os.MkdirAll on the parent directory of the auth file path fails (internal/auth/kimi/kimi/token.go:86-88). The proxy creates auths/<name>.json for Kimi credentials and must create the directory first; failure is a filesystem-level problem such as a read-only volume or missing permissions.","triggerScenarios":"Auth directory path (filepath.Dir(authFilePath)) pointing somewhere unwritable: /auths on a read-only rootfs, a path under a directory owned by another user, Docker mount lacking write permission, or a path component that is actually a file.","commonSituations":"Running the CLIProxyAPI container with a read-only or incorrectly mounted volume for auths/; running as a non-root user against a root-owned directory; misconfigured auth-dir in config.yaml pointing at a nonexistent drive/path.","solutions":["Check the auth file path config (auths dir) and ensure the full parent path exists and is writable: mkdir -p auths && chown $(whoami) auths","If in Docker, mount the auths directory read-write (e.g. -v ./auths:/app/auths) instead of read-only","Verify no regular file occupies any path component of the target directory","Run with a user that has write permission on the parent directory (0700 perms are requested)"],"exampleFix":"# before: container runs with read-only root filesystem and no writable auths mount\ndocker run --read-only ... cli-proxy-api\n# after: mount a writable auths volume\ndocker run --read-only -v \"$PWD/auths:/app/auths\" ... cli-proxy-api","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(authFilePath)\nif info, err := os.Stat(dir); err == nil && !info.IsDir() {\n    return fmt.Errorf(\"auth path parent %q is not a directory\", dir)\n}\nif err := os.MkdirAll(dir, 0700); err != nil {\n    return fmt.Errorf(\"cannot prepare auth dir %q: %w\", dir, err)\n}","typeGuard":null,"tryCatchPattern":"if err := ts.SaveTokenToFile(path); err != nil {\n    if strings.Contains(err.Error(), \"failed to create directory\") {\n        log.Errorf(\"auth dir not writable: %s; fix mounts/permissions\", filepath.Dir(path))\n    }\n    return err\n}","preventionTips":["Pre-create and chown the auths directory in deployment scripts","Mount auths/ read-write in containers","Add a startup probe that writes a temp file under the auth dir and fails fast"],"tags":["filesystem","kimi","auth","permissions"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}