{"record":{"id":"d4800ad47cbe03d4","repo":"router-for-me/CLIProxyAPI","slug":"vertex-credential-create-file-failed-w","errorCode":null,"errorMessage":"vertex credential: create file failed: %w","messagePattern":"vertex credential: create file failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/auth/vertex/vertex_credentials.go","lineNumber":71,"sourceCode":"\t}\n\tif s.ServiceAccount == nil {\n\t\treturn fmt.Errorf(\"vertex credential: service account content is empty\")\n\t}\n\t// Ensure we tag the file with the provider type.\n\ts.Type = \"vertex\"\n\n\tif err := os.MkdirAll(filepath.Dir(authFilePath), 0o700); err != nil {\n\t\treturn fmt.Errorf(\"vertex credential: create directory failed: %w\", err)\n\t}\n\n\tdata, errMerge := misc.MergeMetadata(s, s.Metadata)\n\tif errMerge != nil {\n\t\treturn fmt.Errorf(\"vertex credential: merge metadata failed: %w\", errMerge)\n\t}\n\n\tf, err := os.Create(authFilePath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"vertex credential: create file failed: %w\", err)\n\t}\n\tdefer func() {\n\t\tif errClose := f.Close(); errClose != nil {\n\t\t\tlog.Errorf(\"vertex credential: failed to close file: %v\", errClose)\n\t\t}\n\t}()\n\tenc := json.NewEncoder(f)\n\tenc.SetIndent(\"\", \"  \")\n\tif err = enc.Encode(data); err != nil {\n\t\treturn fmt.Errorf(\"vertex credential: encode failed: %w\", err)\n\t}\n\treturn nil\n}\n","sourceCodeStart":53,"sourceCodeEnd":85,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/auth/vertex/vertex_credentials.go#L53-L85","documentation":"Returned by VertexCredentialStorage.SaveTokenToFile when os.Create fails on the target credential file after the directory was successfully created (vertex_credentials.go:69-72). The file path itself cannot be opened for writing: it may be an existing directory, permission-denied within a 0700 dir owned by another user, name too long, or the filesystem is full.","triggerScenarios":"Target path exists as a directory; dir perms 0700 owned by a different UID than the process; ENOSPC; immutable attribute set on an existing file.","commonSituations":"Leftover directory named like the credential file under auths/; switching the process user after files were created by root; disk exhaustion in long-running deployments.","solutions":["Check the target path type and permissions: ls -ld auths/vertex*.json; remove any directory occupying the filename","Align ownership: chown -R <run-user> auths/ (mode 0700 is enforced for the dir)","Free disk space if os.Create fails with ENOSPC (check df -h)","Retry the Vertex auth setup so a complete credential file is written"],"exampleFix":"# before\n$ ls -ld auths/vertex-abc.json\n drwxr-xr-x 2 root root ... auths/vertex-abc.json   # a directory!\n# after\nrm -rf auths/vertex-abc.json && chown -R appuser auths/","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(authFilePath); err == nil && info.IsDir() {\n    return fmt.Errorf(\"credential path %q is a directory\", authFilePath)\n}","typeGuard":null,"tryCatchPattern":"if err := s.SaveTokenToFile(path); err != nil && strings.Contains(err.Error(), \"create file failed\") {\n    log.Errorf(\"cannot create %s: check perms/disk/path collisions\", path)\n}","preventionTips":["Keep auth file paths collision-free (no directories named like files)","Align process user with auth dir ownership (0700)","Monitor free space on the auth volume"],"tags":["filesystem","vertex","auth","permissions"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}