Skip to content

[BUG] optimize: silent exit on permission denied during App State Cleanup #438

@liamchalcroft

Description

@liamchalcroft

Describe the bug

mo optimize crashes silently with exit code 1 during "App State Cleanup" when it encounters a .savedState directory that requires Full Disk Access permissions. Instead of skipping the protected directory and continuing, the script terminates.

Steps to reproduce

  1. Run command: mo optimize
  2. Script proceeds normally through "DNS & Spotlight Check" and "Finder Cache Refresh"
  3. Script crashes during "App State Cleanup" when encountering a permission-denied directory

Expected behavior

The script should gracefully skip directories it cannot access due to permission restrictions and continue with the remaining optimization tasks.

Debug logs

mo optimize --debug
Debug output
[DEBUG] === App Saved State Cleanup ===
[DEBUG] Remove old application saved states
[DEBUG] Method: Find and remove .savedState folders older than 30 days
[DEBUG] Location: /Users/liamchalcroft/Library/Saved Application State
[DEBUG] Expected outcome: Reduced disk usage, apps start with clean state
[DEBUG] Risk Level: LOW, Old saved states, apps will create new ones
[2026-02-09 11:48:26] DEBUG: Removing: /Users/liamchalcroft/Library/Saved Application State/net.maxon.appinstaller.savedState
[2026-02-09 11:48:26] DEBUG: get_path_size_kb: Failed to get size for /Users/liamchalcroft/Library/Saved Application State/net.maxon.appinstaller.savedState (returned: )
[2026-02-09 11:48:26] DEBUG: Permission denied: /Users/liamchalcroft/Library/Saved Application State/net.maxon.appinstaller.savedState, may need Full Disk Access

Environment

Mole version 1.25.0
macOS: 26.2
Architecture: arm64
Kernel: 25.2.0
SIP: Enabled
Disk Free: 11Gi
Install: Homebrew
Shell: /bin/bash

Additional context

The safe_remove function appears to fail in a way that causes the set -e flag to terminate the script, rather than catching the error and continuing. The problematic directory is net.maxon.appinstaller.savedState which has restricted permissions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions