-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: handle EACCES permission error when creating data directories #6349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
fix: handle EACCES permission error when creating data directories #6349
Conversation
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]>
There was a problem hiding this 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
ensureDirhelper function with EACCES error handling - Replaced direct
fs.mkdircalls 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.
| 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 | ||
| `) |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
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.
| 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) |
| sudo chown -R $(whoami) ${parent} | ||
| Or set a custom data directory: | ||
| export XDG_DATA_HOME=~/.opencode-data |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
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.
| export XDG_DATA_HOME=~/.opencode-data | |
| export XDG_DATA_HOME="$HOME/.opencode-data" |
| 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), |
Copilot
AI
Dec 29, 2025
There was a problem hiding this comment.
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.
- 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]>
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