golang/go · error
%s exists but is not executable
Error message
%s exists but is not executable
What it means
Thrown by the exists command (with -exec flag) in the Go test script framework when a file exists but has no execute permission bits set (mode & 0o111 == 0). This check is skipped on Windows (runtime.GOOS != "windows"). The command asserts that files should be executable.
Source
Thrown at src/cmd/internal/script/cmds.go:617
default:
break loop
}
}
if len(args) == 0 {
return nil, ErrUsage
}
for _, file := range args {
file = s.Path(file)
info, err := os.Stat(file)
if err != nil {
return nil, err
}
if readonly && info.Mode()&0222 != 0 {
return nil, fmt.Errorf("%s exists but is writable", file)
}
if exec && runtime.GOOS != "windows" && info.Mode()&0111 == 0 {
return nil, fmt.Errorf("%s exists but is not executable", file)
}
}
return nil, nil
})
}
// Grep checks that file content matches a regexp.
// Like stdout/stderr and unlike Unix grep, it accepts Go regexp syntax.
//
// Grep does not modify the State's stdout or stderr buffers.
// (Its output goes to the script log, not stdout.)
func Grep() Cmd {
return Command(
CmdUsage{
Summary: "find lines in a file that match a pattern",
Args: matchUsage + " file",
Detail: []string{View on GitHub (pinned to b6b368adc5)
Solutions
- Run `chmod 0755 file` in the script before the exists -exec check.
- Use `cp -perm=0755` or ensure the build step produces an executable-mode file.
- On Windows this check is skipped; ensure you're testing on the intended platform.
Example fix
// Before: // exists -exec mybin // // After (add chmod first): // chmod 0755 mybin // exists -exec mybin
Defensive patterns
Strategy: validation
Validate before calling
// Ensure file is executable before asserting exists -exec:
// In the test script:
// chmod 0755 mybin
// exists -exec mybin
// Programmatic check:
func ensureExecutable(path string) error {
info, err := os.Stat(path)
if err != nil { return err }
if runtime.GOOS != "windows" && info.Mode() & 0111 == 0 {
return os.Chmod(path, info.Mode()|0100)
}
return nil
} Prevention
- Always chmod binaries to include execute bits before exists -exec assertions.
- Use 0755 for executables in test scripts.
- Ensure cp or build steps preserve or set executable permissions.
When it happens
Trigger: exists -exec <file> is called on a non-Windows platform and os.Stat returns a mode where none of the three execute bits (0o100, 0o010, 0o001) are set. The check is `info.Mode()&0111 == 0`.
Common situations: Test script builds or copies a binary but doesn't set the executable bit, then asserts it should be executable. Common after `cp` without preserving mode, or when creating a file from content without chmod. Also happens with cross-compiled binaries that haven't been chmod'd.
Related errors
- %s exists but is writable
- %s and %s differ
- found %d matches for %#q in %s
- no match for %#q in %s
- ErrUnexpectedSuccess
AI-assisted analysis of golang/go@b6b368adc5 (2026-08-12).
Data as JSON: /api/errors/355cd5b35e15d54e.
Report an issue: GitHub.