router-for-me/CLIProxyAPI · error

vertex credential: create file failed: %w

Error message

vertex credential: create file failed: %w

What it means

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.

Source

Thrown at internal/auth/vertex/vertex_credentials.go:71

	}
	if s.ServiceAccount == nil {
		return fmt.Errorf("vertex credential: service account content is empty")
	}
	// Ensure we tag the file with the provider type.
	s.Type = "vertex"

	if err := os.MkdirAll(filepath.Dir(authFilePath), 0o700); err != nil {
		return fmt.Errorf("vertex credential: create directory failed: %w", err)
	}

	data, errMerge := misc.MergeMetadata(s, s.Metadata)
	if errMerge != nil {
		return fmt.Errorf("vertex credential: merge metadata failed: %w", errMerge)
	}

	f, err := os.Create(authFilePath)
	if err != nil {
		return fmt.Errorf("vertex credential: create file failed: %w", err)
	}
	defer func() {
		if errClose := f.Close(); errClose != nil {
			log.Errorf("vertex credential: failed to close file: %v", errClose)
		}
	}()
	enc := json.NewEncoder(f)
	enc.SetIndent("", "  ")
	if err = enc.Encode(data); err != nil {
		return fmt.Errorf("vertex credential: encode failed: %w", err)
	}
	return nil
}

View on GitHub (pinned to 78f0c4079e)

Solutions

  1. Check the target path type and permissions: ls -ld auths/vertex*.json; remove any directory occupying the filename
  2. Align ownership: chown -R <run-user> auths/ (mode 0700 is enforced for the dir)
  3. Free disk space if os.Create fails with ENOSPC (check df -h)
  4. Retry the Vertex auth setup so a complete credential file is written

Example fix

# before
$ ls -ld auths/vertex-abc.json
 drwxr-xr-x 2 root root ... auths/vertex-abc.json   # a directory!
# after
rm -rf auths/vertex-abc.json && chown -R appuser auths/
Defensive patterns

Strategy: validation

Validate before calling

if info, err := os.Stat(authFilePath); err == nil && info.IsDir() {
    return fmt.Errorf("credential path %q is a directory", authFilePath)
}

Try / catch

if err := s.SaveTokenToFile(path); err != nil && strings.Contains(err.Error(), "create file failed") {
    log.Errorf("cannot create %s: check perms/disk/path collisions", path)
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/d4800ad47cbe03d4. Report an issue: GitHub.