opencode
opencode copied to clipboard
fix: Enhance clipboard error handling by propagating errors and checking command exit codes
Overview
This pull request improves clipboard functionality by enhancing error handling across all platforms, with particular focus on Linux systems. The changes ensure that clipboard operations properly propagate errors and provide meaningful feedback to users when issues occur.
Changes
1. Clipboard.ts (util/clipboard.ts)
-
Linux Wayland support: Added proper detection for Wayland environments via
WAYLAND_DISPLAYenvironment variable -
Exit code validation: Added checks for command exit codes (0 means success) for all clipboard tools:
-
wl-copy(Wayland) -
xclip(X11) -
xsel(X11)
-
- Improved error handling: Tools now throw descriptive errors when clipboard operations fail, instead of silently failing
- Better error messages: Specific error messages indicate which tool failed and what to install if tools are missing
2. App.tsx (ui/app.tsx)
- Error propagation: Updated clipboard.copy() calls to properly handle errors
- User feedback: Added error toast notifications when clipboard operations fail
- Graceful degradation: Users are informed when copy operation fails instead of silent failure
Technical Details
- Changed from
.catch(() => {})(silent failures) to.catch((error) => { ... })(proper error handling) - Exit codes are now properly checked for spawned processes
- Error messages clearly indicate the issue and suggest resolution steps
Testing
- [ ] Tested clipboard copy on Linux with Wayland
- [ ] Tested clipboard copy on Linux with X11
- [ ] Tested clipboard copy on Windows
- [ ] Tested clipboard copy on macOS
- [ ] Verified error messages display correctly when tools are missing
Related Issues
Closes #[issue-number] (if applicable)
Checklist
- [x] Changes follow the project's contributing guidelines
- [x] Code is properly formatted
- [x] Error handling is comprehensive
- [x] User-facing messages are clear and helpful