I had the same recently, while almost 3TB of flash storage in my Mac Studio were still seemingly available.
What the Finder told me just wasn't the truth.
In actual fact Time Machine had silently stuffed the drive full of snapshots of many temporary files and had failed to clean those up when the actual space on the drive really got tight while the Finder still kept pretending that there was plenty of space – Safari, Mail and other programs suffered from the drive actually being almost completely full while Finder still effectively lied to me about it, as did Disk Utility.
The situation got really bad and I ultimately couldn't see most of my mails and Safari would not open most pages any more (with that same error message above!), even after flushing caches, emptying the trash and rebooting.
After losing multiple billable working hours and getting into more and more trouble because I couldn't access my mails any more I ultimately found the cause when I let Disk Utility run a full volume First Aid which very slowly chewed through 24 lines like these in total:
Checking the snapshot metadata.
Checking snapshot 1 of 24 (com.apple.TimeMachine.2022-12-05-061759.local)
Checking snapshot 2 of 24 (com.apple.TimeMachine.2022-12-07-151506.local)
[...]
Checking snapshot 23 of 24 (com.apple.TimeMachine.2022-12-08-131958.local)
Checking snapshot 24 of 24 (com.apple.TimeMachine.2022-12-08-142002.local)
Checking the document ID tree.
Since I'm very diligent with backing up to multiple local (on- and offsite rotated) external drives I knew I did not actually need my main drive stuffed with local Time Machine snapshots on top, so I dropped to Terminal and ran:
tmutil listlocalsnapshots /
which showed me those reported snapshots being present and then I ran:
df -g;tmutil thinlocalsnapshots / 500000000000 4;df -g
The before and after disk space listings were almost identical - no hint of the disk actually having been completely full before and mostly empty afterwards, but when I then rebooted again everything was fine again: Mail sees all my mails again and Safari loads all the pages as if nothing ever happened!
I actually had an even worse problem early after the switch to the new APFS file system a few years ago on my old Intel Mac where I actually had lost data due to the same problem: Multiple programs were unable to save open documents to the actually full drive even though Finder had pretended there was still enough space) so changes and settings were completely lost and multiple files were truncated to empty which lost me a lot of work.
My hope that this problem was fixed by now was just unfortunately in vain.
What is the problem:
- Local Time Machine snapshots would be a good idea in principle.,
- ...If they were automatically thinned out when the disk was filling up,
- ...if they didn't grab every random temporary file and didn't try to keep if forever,
- ...if they were handled reasonably when actual external backups are made and
- ...if the Finder wasn't lying to me about the space they actually do occupy!
But unfortunately that is the behaviour I had seen earlier (where I then regularly and manually flushed the local snapshots on my old machine like above) and which is still the case even now, on brand-new machines and in up-to-date Monterey in my case (I'm not upgrading to Ventura before the first major sub-version) which is a major disappointment because this is a really bad problem exactly because the system actively hides the cause.
APFS is great in principle, but this aspect is a real problem, and it is still apparently unfixed!
(I had had a major support event back then but apparently no conclusions were drawn to fix the APFS behaviour in this respect so years later it hit me again.)
So this description adds to the time I have now lost from this but maybe it can help some others to at least cope with it and maybe, maybe the actual root cause gets fixed too, some day...!