Skip to content

Conversation

@jayhemnani9910
Copy link

When ~/.local/share exists with restrictive permissions (e.g., created by PowerShell or uv), opencode crashes with an unhelpful EACCES error. This adds proper error handling that provides clear remediation steps.

Fixes #6343

When ~/.local/share exists with restrictive permissions (e.g., created by
PowerShell or uv), opencode crashes with an unhelpful EACCES error. This
adds proper error handling that provides clear remediation steps.

Fixes sst#6343

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
Copilot AI review requested due to automatic review settings December 29, 2025 11:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves error handling when opencode fails to create data directories due to permission issues. When ~/.local/share or other XDG directories exist with restrictive permissions (commonly created by tools like PowerShell or uv), the application now provides clear, actionable error messages instead of crashing with a generic EACCES error.

  • Added ensureDir helper function with EACCES error handling
  • Replaced direct fs.mkdir calls with the new error-handling wrapper
  • Provides user-friendly remediation steps when permission errors occur

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 29 to 40
console.error(`
Error: Permission denied creating directory: ${dir}
The parent directory "${parent}" exists but opencode cannot write to it.
This can happen when another application created it with restrictive permissions.
To fix this, run:
sudo chown -R $(whoami) ${parent}
Or set a custom data directory:
export XDG_DATA_HOME=~/.opencode-data
`)
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The remediation command uses Unix-specific syntax with sudo, chown, and $(whoami) which will not work on Windows. Since the PR description mentions PowerShell as a scenario, this error message should provide cross-platform remediation steps or detect the OS and provide appropriate commands.

Suggested change
console.error(`
Error: Permission denied creating directory: ${dir}
The parent directory "${parent}" exists but opencode cannot write to it.
This can happen when another application created it with restrictive permissions.
To fix this, run:
sudo chown -R $(whoami) ${parent}
Or set a custom data directory:
export XDG_DATA_HOME=~/.opencode-data
`)
const isWindows = process.platform === "win32"
const remediation = isWindows
? [
"On Windows, adjust the folder permissions so your user can write to it.",
"For example, in an elevated PowerShell prompt you can run:",
` icacls "${parent}" /grant "${process.env.USERNAME}:(OI)(CI)M" /T`,
].join("\n")
: [
"To fix this on Unix-like systems, run:",
` sudo chown -R $(whoami) "${parent}"`,
].join("\n")
const dataDirInstruction = isWindows
? ' $env:XDG_DATA_HOME="$HOME\\.opencode-data"'
: " export XDG_DATA_HOME=~/.opencode-data"
const message = [
`Error: Permission denied creating directory: ${dir}`,
"",
`The parent directory "${parent}" exists but opencode cannot write to it.`,
"This can happen when another application created it with restrictive permissions.",
"",
remediation,
"",
"Or set a custom data directory:",
` ${dataDirInstruction}`,
"",
].join("\n")
console.error(message)

Copilot uses AI. Check for mistakes.
sudo chown -R $(whoami) ${parent}
Or set a custom data directory:
export XDG_DATA_HOME=~/.opencode-data
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tilde (~) in the export command may not expand correctly in all shells. Use $HOME/.opencode-data instead of ~/.opencode-data for more reliable cross-shell compatibility.

Suggested change
export XDG_DATA_HOME=~/.opencode-data
export XDG_DATA_HOME="$HOME/.opencode-data"

Copilot uses AI. Check for mistakes.
Comment on lines 25 to +52
await Promise.all([
fs.mkdir(Global.Path.data, { recursive: true }),
fs.mkdir(Global.Path.config, { recursive: true }),
fs.mkdir(Global.Path.state, { recursive: true }),
fs.mkdir(Global.Path.log, { recursive: true }),
fs.mkdir(Global.Path.bin, { recursive: true }),
ensureDir(Global.Path.data),
ensureDir(Global.Path.config),
ensureDir(Global.Path.state),
ensureDir(Global.Path.log),
ensureDir(Global.Path.bin),
Copy link

Copilot AI Dec 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When multiple directories fail with EACCES in Promise.all, only the first error will be caught and reported. The other promises will be rejected silently. Consider catching errors individually in each ensureDir call so that the most informative error message is shown, or aggregate all errors before reporting.

Copilot uses AI. Check for mistakes.
jayhemnani9910 and others added 2 commits December 29, 2025 14:21
- Add Windows-specific remediation using icacls command
- Use $HOME instead of ~ for better shell compatibility
- Restructure message for cleaner formatting

Addresses Copilot review feedback.

Signed-off-by: Jay Hemnani <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EACCES: permission denied, mkdir '/Users/user/.local/share/opencode'

1 participant