larksuite/cli · error

%s: cannot retrieve file owner for %q

Error message

%s: cannot retrieve file owner for %q

What it means

After stat succeeds, checkOwnerUID extracts the raw syscall.Stat_t via stat.Sys() to read the owner UID. On platforms or filesystems where the syscall-specific stat structure is unavailable, the type assertion fails and this error is thrown. It is a defensive guard: without owner information the security audit cannot proceed safely, so it fails closed.

Source

Thrown at internal/binding/audit_unix.go:24

package binding

import (
	"fmt"
	"os"
	"syscall"

	"github.com/larksuite/cli/internal/vfs"
)

// checkOwnerUID verifies the file is owned by the current user.
func checkOwnerUID(path, label string) error {
	stat, err := vfs.Stat(path)
	if err != nil {
		return fmt.Errorf("%s: cannot stat %q: %w", label, path, err)
	}
	sysStat, ok := stat.Sys().(*syscall.Stat_t)
	if !ok {
		return fmt.Errorf("%s: cannot retrieve file owner for %q", label, path)
	}
	if sysStat.Uid != uint32(os.Getuid()) {
		return fmt.Errorf("%s: path %q is owned by uid %d, expected %d",
			label, path, sysStat.Uid, os.Getuid())
	}
	return nil
}

// auditFilePermissions rejects world/group-writable modes (always) and
// world/group-readable modes (unless allowReadableByOthers is true, which
// exec commands typically need for their usual 755 mode).
func auditFilePermissions(effectivePath string, allowReadableByOthers bool, label string) error {
	info, err := vfs.Stat(effectivePath)
	if err != nil {
		return fmt.Errorf("%s: cannot stat %q: %w", label, effectivePath, err)
	}
	mode := info.Mode().Perm()

View on GitHub (pinned to 7fd6ef3c07)

Solutions

  1. Run the CLI on a supported Unix platform (Linux/macOS) with a standard filesystem
  2. Ensure the file lives on a regular local filesystem, not a shim that hides syscall metadata
  3. If you maintain a custom vfs backend, return the platform's real *syscall.Stat_t from Sys()
  4. Report the platform combination to the maintainers if it should be supported
Defensive patterns

Strategy: type-guard

Validate before calling

if fi, err := os.Stat(path); err == nil {
  if _, ok := fi.Sys().(*syscall.Stat_t); !ok {
    return fmt.Errorf("platform cannot expose owner uid for %s", path)
  }
}

Type guard

func hasSysStat(fi fs.FileInfo) (*syscall.Stat_t, bool) {
  st, ok := fi.Sys().(*syscall.Stat_t)
  return st, ok
}

Prevention

When it happens

Trigger: stat.Sys() does not return *syscall.Stat_t — practically only on non-Unix builds that still compile this file (it is guarded by !windows, so this indicates an exotic platform) or a vfs implementation returning a synthetic FileInfo without a real syscall backing.

Common situations: Running on an unusual/unsupported Unix-like platform; a vfs layer that fabricates FileInfo (e.g. tests, FUSE-like shims) without a real Stat_t; cross-compiled binary running under an emulation layer with incomplete stat support.

Related errors


AI-assisted analysis of larksuite/cli@7fd6ef3c07 (2026-09-04). Data as JSON: /api/errors/350b878bf6312cbc. Report an issue: GitHub.