yorukot/superfile · error
error saving pinned directories: %w
Error message
error saving pinned directories: %w
What it means
Toggle adds or removes a directory in the pinned list and then persists the list via mgr.Save. This error wraps any error returned by Save (JSON marshal or file write failure), attributing it to the save step of toggling. The in-memory toggle itself has already happened, so the error indicates the change was not persisted.
Source
Thrown at src/internal/ui/sidebar/pinned.go:84
unPinned := false
for i, other := range dirs {
if other.Location == dir {
dirs = append(dirs[:i], dirs[i+1:]...)
unPinned = true
break
}
}
if !unPinned {
dirs = append(dirs, directory{
Location: dir,
Name: filepath.Base(dir),
})
}
if err := mgr.Save(dirs); err != nil {
return fmt.Errorf("error saving pinned directories: %w", err)
}
return nil
}
// Clean removes non-existing directories and optionally saves the updated list
func (mgr *PinnedManager) Clean(dirs []directory) []directory {
cleanedDirs := make([]directory, 0, len(dirs))
for _, dir := range dirs {
if _, err := os.Stat(dir.Location); err == nil {
cleanedDirs = append(cleanedDirs, dir)
} else if !os.IsNotExist(err) {
slog.Warn("error while checking pinned directory", "directory", dir.Location, "error", err)
}
}
if len(cleanedDirs) == len(dirs) {
return cleanedDirsView on GitHub (pinned to b72f550bc6)
Solutions
- Ensure the config directory exists and is writable before calling Toggle
- Check pinned.json permissions (read-only file causes write failure)
- Inspect the wrapped error chain for the root OS cause
- Re-create the config directory if it was removed
Example fix
// before
if err := mgr.Toggle(dir); err != nil {
return err
}
// after
if err := os.MkdirAll(filepath.Dir(mgr.FilePath()), 0o755); err != nil {
return fmt.Errorf("cannot prepare config dir: %w", err)
}
if err := mgr.Toggle(dir); err != nil {
return err
} Defensive patterns
Strategy: try-catch
Validate before calling
if _, err := os.Stat(filepath.Dir(mgr.filePath)); os.IsNotExist(err) {
os.MkdirAll(filepath.Dir(mgr.filePath), 0o755)
} Try / catch
if err := mgr.Toggle(dir); err != nil {
var wrapped interface{ Unwrap() error }
if errors.As(err, &errors.Wrapper{}) || err.Error() != "" {
log.Printf("toggle not persisted: %v", err)
}
} Prevention
- Ensure config dir exists before UI interactions that call Toggle
- Verify file permissions after packaging/installing the app
- Handle the error in the UI so users know the pin was not saved
- Test toggle behavior with a read-only HOME in CI
When it happens
Trigger: Calling Toggle with any directory when the underlying Save fails: unwritable config file, missing parent directory, marshal failure, or disk full.
Common situations: Users pinning a directory in an environment where the config directory was deleted mid-session, or where the pinned.json file is owned by another user or made read-only.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- error writing pinned directories file: %w
- failed to get absolute path of the first path: %w
- failed to get absolute path of the second path: %w
- failed to get entry info: %w
- failed to open source file: %w
AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01).
Data as JSON: /api/errors/2e600a02c64672b9.
Report an issue: GitHub.